hdu 1785
http://acm.hdu.edu.cn/showproblem.php?pid=1785
代码如下:
#include"stdio.h" #include"math.h" #include"stdlib.h" struct nod { double x,y; double num; }a[105]; int cmp(const void *a,const void *b) { nod *aa=(nod*)a,*bb=(nod*)b; return aa->num>bb->num?1:-1; } int main( ) { int n,i; while(scanf("%d",&n)&&n>=0) { for(i=0;i<n;i++) { scanf("%lf%lf",&a[i].x,&a[i].y); if(a[i].x==0) a[i].num=acos(-1.0)/2; else if(a[i].x<0) a[i].num=acos(-1.0)+atan(a[i].y/a[i].x);//注意这里,当tan是负的时候,其反函数也是负的 else a[i].num=atan(a[i].y/a[i].x); } qsort(a,n,sizeof(nod),cmp); for(i=0;i<n;i++) { if(i==0) printf("%.1lf %.1lf",a[i].x,a[i].y); else printf(" %.1lf %.1lf",a[i].x,a[i].y); } printf("\n"); } }