您的位置:首页 > 编程语言 > Go语言

POJ 2007 Scrambled Polygon (简单极角排序)

2014-08-28 14:07 561 查看
题目链接

题意 : 对输入的点极角排序

思路 : 极角排序方法

#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>

using namespace std;

struct point
{
double x,y;
}p[50],pp;
double cross(point a,point b,point c)
{
return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y) ;
}
bool cmp(point a,point b)
{
int cr = cross(a,b,pp) ;//判断顺时针还是逆时针
if(cr > 0) return true ;
else if(cr < 0) return false ;
}
int main()
{
int cnt = 0;
while (scanf("%lf %lf",&p[cnt].x,&p[cnt].y) != EOF)
{
++cnt;
}
pp.x = pp.y = 0 ;
sort(p+1,p+cnt,cmp);
for (int i = 0 ; i < cnt ; i++)
{
cout<<"("<<p[i].x<<","<<p[i].y<<")"<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: