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 ACM_ddtc at 2010-07-29 09:29:57 on Problem 2187
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
#define EPS 1e-8
typedef struct point{int x;int y;double angle;}point;
int comp(point &a,point &b)
{
	double r=a.angle-b.angle;
	if(fabs(r)>EPS)
		return r>0?1:-1; 
	else
		return a.x-b.x;
}//角度a>b返回1,否则返回-1,角度相等a.x-b.x
int area(point &p1,point &p2,point &p3)
{
	return (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x);
}//面积
int len(point &a,point &b)
{
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
point st[50002]; int sp;//定义栈
void pop()//出栈
{sp--;}
void push(point &pp)
{
	st[sp].x=pp.x;
	st[sp].y=pp.y;
	st[sp].angle=pp.angle;
	sp++;
}

int main()
{
	int i,N;
	int xt,yt,it;
	cin>>N;
	point pf[50000];
	for(i=0;i<N;i++)
		cin>>pf[i].x>>pf[i].y;
	xt=pf[0].x;yt=pf[0].y;it=0;
	for(i=1;i<N;i++)
	{
		if(pf[i].x<xt)
		{
			xt=pf[i].x;yt=pf[i].y;it=i;
		}
		else if(pf[i].x==xt&&pf[i].y<yt)
		{
			xt=pf[i].x;yt=pf[i].y;it=i;
		}
	}
	pf[it].x=pf[0].x;
	pf[it].y=pf[0].y;
	pf[0].x=0;
	pf[0].y=0;
	for(i=1;i<N;i++)
	{
		pf[i].x-=xt;pf[i].y-=yt;
		pf[i].angle=atan2((double)pf[i].y,(double)pf[i].x);
	}
	sort(pf+1,pf+N,comp);
	push(pf[0]);push(pf[1]);
	for(i=2;i<N;i++)
	{
		while(area(st[sp-2],st[sp-1],pf[i])<0)
			pop();
		push(pf[i]);
	}
	int l,length=0;
	for(i=0;i<sp-1;i++)
		for(int j=i;j<sp;j++)
			if((l=len(st[i],st[j]))>length)
				length=l;
	cout<<length<<endl;
	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