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

...RE的怎么破= =

Posted by dong_123 at 2013-03-04 09:07:00 on Problem 2187
/*
PROG: 旋转卡壳 
LANG: C++
ID: dong_li1
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef struct{
	int x,y;
}point;
point p[100100],q[100100];
int n,minn=0,top=0;
int dist(point p1,point p2){
	return((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
int multiply(point p1,point p2,point o){
	return((p1.x-o.x)*(p2.y-o.y)-(p1.y-o.y)*(p2.x-o.x));
}
bool cmp(point p1,point p2){
	return((multiply(p1,p2,p[minn])>0)||(multiply(p1,p2,p[minn])==0&&dist(p1,p[minn])>dist(p1,p[minn])));
}
void Graham_Scan(){
	swap(p[0],p[minn]);
	sort(p+1,p+n,cmp);
	q[1]=p[0];q[2]=p[1];q[3]=p[2];top=3;
	for(int i=3;i<n;i++){
		while(multiply(q[top],p[i],q[top-1])<=0&&top>1) top--;
		q[++top]=p[i];
	}
}
int Get_D(){
	int pos,ans;
	p[n]=p[0];
	for(int i=1;i<=top;i++){
		while(multiply(p[i+1],p[pos+1],p[i])>multiply(p[i+1],p[pos],p[i]))
			pos=(pos+1)%top;
		ans=max(ans,max(dist(p[i],p[pos]),dist(p[i+1],p[pos+1])));
	}
	return(ans);
}
int main(){
	scanf("%d\n",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d\n",&p[i].x,&p[i].y);
		if(p[i].y<q[minn].y||(p[i].y==q[minn].y&&p[i].x<q[minn].x)) minn=i;
	}
	if(n>2){
	Graham_Scan();
	printf("%d\n",Get_D());
	}else
		printf("%d\n",dist(p[0],p[1]));
}

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