华师大 OJ 3059

题目链接:点击打开链接


解决方案:

/******************************************************************************/
/*                                                                            */
/*  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);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值