| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
不是说一定是凸多边形么?那么我为什么直接对极角排序再输出会WA?牛们帮我看看吧,谢谢#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
struct Tpoint{int x,y;}P[55];
double multi(Tpoint p0,Tpoint p1,Tpoint p2){return double((p1.x-p0.x)*(p2.y-p0.y))-double((p2.x-p0.x)*(p1.y-p0.y));}
int cmp1(Tpoint a,Tpoint b){return (a.y<b.y)||((a.y==b.y)&&(a.x<b.x));}
int cmp2(Tpoint a,Tpoint b){return multi(P[0],a,b)>0;}
int main()
{
int i,j,n=0;
while(scanf("%d%d",&P[n].x,&P[n].y)!=EOF)
n++;
sort(P,P+n,cmp1);
sort(P,P+n,cmp2);
for(i=0;i<n;i++)
{
if(P[i].x==0&&P[i].y==0)
break;
}
for(j=0;j<n;j++,i++)
printf("(%d,%d)\n",P[i%n].x,P[i%n].y);
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator