Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不是说一定是凸多边形么?那么我为什么直接对极角排序再输出会WA?牛们帮我看看吧,谢谢

Posted by narutomj at 2010-04-07 23:54:20 on Problem 2007
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator