3 5.0 4.0 3.1 0.1 2.0 2.0 -1
3.1 0.1 5.0 4.0 2.0 2.0
#include<iostream> #include<algorithm> using namespace std; struct person { int flag; double x; double y; double angle; }per[101]; bool cmp(person t,person h) { return t.angle<h.angle; } int main() { int n,j; while(cin>>n&&n>0) { for(int m=0;m<101;m++) {per[m].x=0; per[m].y=0; per[m].angle=0; per[m].flag=0; } for(int i=0;i<n;i++) { cin>>per[i].x>>per[i].y; if(per[i].x<0) {per[i].x=-per[i].x;per[i].flag=1;} if(per[i].x==0) per[i].angle=-1; else per[i].angle=per[i].y/per[i].x; //cout<<"per[i]="<<per[i].x<<" "<<per[i].y<<endl; } sort(per,per+n,cmp); int c=0; for( j=0;j<n-1;j++) { if(per[j].angle==-1) { c=j+1;continue; } printf(per[j].flag?"-%.1lf %.1lf ":"%.1lf %.1lf ",per[j].x,per[j].y); } if(c) {//cout<<"liangshu"<<endl; printf(per[j].flag?"-%.1lf %.1lf ":"%.1lf %.1lf ",per[j].x,per[j].y); printf("%.1lf %.1lf\n",per[c-1].x,per[c-1].y); } else printf(per[j].flag?"-%.1lf %.1lf\n":"%.1lf %.1lf\n",per[j].x,per[j].y); } return 0; }
#include<iostream> #include<cmath> #include<algorithm> using namespace std; struct person { double x; double y; double angle; }per[101]; bool cmp(person a,person b) { return a.angle<b.angle; } int main() { int n,j; while(cin>>n&&n>0) { for(int i=0;i<n;i++) { cin>>per[i].x>>per[i].y; per[i].angle=fabs(atan2(per[i].y,per[i].x)); } sort(per,per+n,cmp); for( j=0;j<n-1;j++) printf("%.1lf %.1lf ",per[j].x,per[j].y); printf("%.1lf %.1lf\n",per[j].x,per[j].y); } return 0; }
杭电 HDU ACM 1785 You Are All Excellent
原文地址:http://blog.csdn.net/lsgqjh/article/details/44925701