题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1785
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
思路:
用反三角函数 angle = atan(y,x),再比较大小即可!
代码如下:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct num
{
double x, y;
double angle;
} a[117];
bool cmp(num a, num b)
{
return a.angle < b.angle;
}
int main()
{
int n;
while(~scanf("%d",&n) && n >= 0)
{
for(int i = 0; i < n; i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
a[i].angle = atan2(a[i].y,a[i].x);
}
sort(a,a+n,cmp);
printf("%.1lf %.1lf",a[0].x,a[0].y);
for(int i = 1; i < n; i++)
{
printf(" %.1lf %.1lf",a[i].x,a[i].y);
}
printf("\n");
}
return 0;
}
HDU 1785 You Are All Excellent(数学题)
原文地址:http://blog.csdn.net/u012860063/article/details/39298401