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 tiler at 2011-08-08 15:48:45 on Problem 2187
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define MAXN 50005
#define eps 1e-8
const double pi = acos(-1.0);
double ans;
struct point
{
	double x, y;
};
point p[MAXN];
int stack[MAXN];
point s;
bool zero(double x)
{
	return ((x)>0?(x):-(x))<eps;
}
double dist(point a, point b)
{
	double p = a.x - b.x, q = a.y - b.y;
	return p*p + q*q;
}
double xmult(point a, point b, point c)
{
	return (c.x - a.x)*(b.y - a.y) - (b.x - a.x)*(c.y - a.y) ;
}
bool cmp(point a, point b)
{
	double t = xmult(s, a, b);
	if (!zero(t))
		return t < 0;
	return
		dist(s, a) > dist(s, b);
}
int graham(int n)
{
	int i;
	for(i=1;i<n;i++)
		if( p[i].y<p[0].y ||( p[i].y==p[0].y && p[i].x<p[0].x ))
			swap(p[i],p[0]);
	s=p[0];
	sort(p+1,p+n,cmp);
	stack[0]=0;
	stack[1]=1;
	int slip=2;
	double t;
	for(i=2;i<n;i++)
	{
		t=xmult(p[0],p[i-1],p[i]);
		if(zero(t))
			continue;
		while (xmult(p[stack[slip-2]], p[stack[slip-1]], p[i]) >eps)
			slip--;
		stack[slip] = i;
		slip++;
	}
	return slip;
}
int main()
{
	int i,j,n,l,ans;
	while (scanf("%d",&n) != EOF)
	{
		for (i = 0;i < n;i++)
			scanf("%lf %lf",&p[i].x,&p[i].y);
		l = graham(n);
		ans = 0;
		j = 1;
		for (i = 0;i < l;i++)
		{
			while (xmult(p[stack[i]],p[stack[j]],p[stack[i + 1]]) < xmult(p[stack[i]],p[stack[j + 1]],p[stack[i + 1]]))
				j = (j + 1) % l;
			ans = max(ans + 0.0,dist(p[stack[i]],p[stack[j]]));
			ans = max(ans + 0.0,dist(p[stack[i + 1]],p[stack[j + 1]]));
		}
		printf("%d\n",ans);
	}
	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