题目链接:点击打开链接
解决方案:
/******************************************************************************/
/* */
/* DON'T MODIFY main() function anyway! */
/* */
/******************************************************************************/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct PolePoint {
double r;
double angle;
};
struct PolePoint record[1000];
void solve(); /*write function solve() to process one case of the problem */
void init(){}
int main()
{ int i,t; init();
scanf("%d\n",&t);
for (i=0;i<t;i++)
{ printf("case #%d:\n",i);
solve();
}
return 0;
}
int cmp(const void *a,const void *b){
struct PolePoint x,y;
x = *((struct PolePoint*)a);
y = *((struct PolePoint*)b);
if(x.angle!=y.angle){
if(x.angle<y.angle) return -1;
else return 1;
} else if(x.angle == y.angle){
if(x.r < y.r) return 1;
else return -1;
}
}
void solve(){
int n;
int i;
int k;
double x,y;
scanf("%d",&n);
for(k=0;k<n;k++){
scanf("%lf %lf",&x,&y);
record[k].r = sqrt(x*x+y*y);
record[k].angle = (atan2(y,x)>=0)?atan2(y,x):atan2(y,x) + 2*M_PI;
}
qsort(record,n,sizeof(record[0]),cmp);
for(k=0; k<n; k++){
printf("(%.4lf,%.4lf)\n",record[k].r,record[k].angle);
}
}