极角排序裸题。。
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
struct point
{
int x,y;
};
const int maxn = 77;
point poly[maxn];
int cross(point p0,point p1,point p2) //计算叉积 p0p1 X p0p2
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
}
double dis(point p1,point p2) //计算 p1p2的 距离
{
return sqrt((double)(p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
}
bool cmp(point p1,point p2) //极角排序函数 , 角度相同则距离小的在前面
{
int tmp=cross(poly[0],p1,p2);
if(tmp>0) return true;
else if(tmp==0&&dis(poly[0],p1)<dis(poly[0],p2)) return true;
else return false;
}
int main()
{
int cnt = 0;
while (~scanf("%d%d", &poly[cnt].x, &poly[cnt].y)) cnt++;
sort(poly, poly + cnt, cmp);
for (int i = 0; i < cnt; i++)
printf("(%d,%d)\n", poly[i].x, poly[i].y);
return 0;
}