7-10 阿生的粉絲團 (30 分)
- 2019 年 11 月 8 日
- 筆記
版權聲明:本文為部落客原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。
本文鏈接:https://blog.csdn.net/shiliang97/article/details/101473111
7-10 阿生的粉絲團 (30 分)
夭折了,阿生竟然有粉絲團了,而且還是清一色的妹子。激動的阿生忍不住咬了自己一下,確定一下不是夢,好吧,還真是個夢。醒來的阿生悲痛欲絕,只想知道夢境中她們平面坐標的逆時針排列,你能幫幫他嗎。
輸入格式:
輸入每行給出一組整數x,y代表夢境中阿生粉絲的平面坐標,並且保證第一個的坐標永遠是(0 0): -1000= x <= 1000, -1000<= y <= 1000
輸出格式:
按照(%d,%d)的格式輸出即可
輸入樣例:
0 0 70 -50 60 30 -30 -50 80 20 50 -60 90 -20 -30 -40 -10 -60 90 10
輸出樣例:
(0,0) (-30,-40) (-30,-50) (-10,-60) (50,-60) (70,-50) (90,-20) (90,10) (80,20) (60,30)
#include<iostream> #include<vector> #include<algorithm> struct node{ int x; int y; }; bool cmp(node n1,node n2){ int f1,f2; if(n1.x==0&&n1.y==0){ f1=5; }if(n2.x==0&&n2.y==0){ f2=5; } if(n1.x>=0&&n1.y>=0){ f1=2; }if(n1.x<=0&&n1.y>0){ f1=1; }if(n1.x<=0&&n1.y<=0){ f1=4; }if(n1.x>=0&&n1.y<0){ f1=3; }if(n2.x>=0&&n2.y>=0){ f2=2; }if(n2.x<=0&&n2.y>0){ f2=1; }if(n2.x<=0&&n2.y<=0){ f2=4; }if(n2.x>=0&&n2.y<0){ f2=3; } if(f1!=f2){ return f1>f2; } else if(f1==4){ f1=n1.x*n2.y; f2=n2.x*n1.y; return f1>f2; }else if(f1==3){ f1=n1.x*n2.y; f2=n2.x*n1.y; return f1>f2; } return n1.x!=n2.x ? n1.x>n2.x:n1.y>n2.y; } using namespace std; int main(){ int a,b; vector<node>no; while(scanf("%d %d",&a,&b)==2){ node n; n.x=a; n.y=b; no.push_back(n); } sort(no.begin(),no.end(),cmp); for(int i=0;i<no.size();i++){ cout<<"("<<no[i].x<<","<<no[i].y<<")"<<endl; } return 0; }