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

贴个AC代码

Posted by 452181625 at 2014-05-20 08:08:10 on Problem 2187
数据类型用int
别用double
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct P
{
	int x,y;
	P(){}
	P(int x,int y):x(x),y(y){
	}
	P operator -(P p){
		return P(x-p.x,y-p.y);//返回一个对象。
	}
	double det(P p){
		return x*p.y-y*p.x;//返回一个数。
	}
};
P p[100005],qs[100005];
bool cmp(P a,P b)
{
	if(a.x!=b.x)
		return a.x<b.x;
	return a.y<b.y;
}
int main()
{
	int i,j,n,maxx,dis;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d%d",&p[i].x,&p[i].y);
	sort(p+1,p+n+1,cmp);
	int k=0;
	for(i=1;i<=n;i++)//保证至少有两个点。
	{
		while(k>1 && (qs[k]-qs[k-1]).det(p[i]-qs[k-1])<=0)
			k--;
		qs[++k]=p[i];
	}
	int t=k;
	for(i=n;i>=1;i--)//保证至少有t个点。
	{
		while(k>t && (qs[k]-qs[k-1]).det(p[i]-qs[k-1])<=0)
			k--;
		qs[++k]=p[i];
	}
	k--;//最后一个点和起点重合。
	maxx=-1;
	for(i=1;i<=k-1;i++)
		for(j=i+1;j<=k;j++)
		{
			dis=(qs[i].x-qs[j].x)*(qs[i].x-qs[j].x)+(qs[i].y-qs[j].y)*(qs[i].y-qs[j].y);
			if(dis>maxx) maxx=dis;
		}
		cout<<maxx<<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