旋转卡壳

传送门:http://blog.csdn.net/ACMaker    http://www.cnblogs.com/Booble/archive/2011/04/03/2004865.html   

       http://www.cnblogs.com/DreamUp/archive/2010/09/16/1828131.html         

 POJ 2187

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
struct point{
	int x,y;
}a[60000];
bool operator ==(const point &a,const point &b){
	return (a.x==b.x)&&(a.y==b.y);
}
	bool cmp(point a,point b){
		if (a.x<b.x) return 1;
		if (a.x>b.x) return 0;
		return a.y<b.y;
	}

point operator +(const point &a,const point &b){
	point c;	
	c.x=a.x+b.x; c.y=a.y+b.y; return c;
}

point operator -(const point &a,const point &b){
	point c;	
	c.x=a.x-b.x; c.y=a.y-b.y; return c;
}

int cross(point a,point b){
return a.x*b.y-b.x*a.y;
}

int dot(point a,point b){
return a.x*b.x+a.y*b.y;
}

int dist(point a,point b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

int d[60000],top,n;
point beg[60000];
int tot=0;

void doit(int op){
int i;
if (op>0) i=1; else i=n;
top=2; d[1]=i; d[2]=i+op;
for (i=i+op*2;(i>=1)&&(i<=n);i+=op){
		while((top>=2)&&(cross(a[d[top-1]]-a[d[top]],a[i]-a[d[top]])>=0))
			top--;
		d[++top]=i;
	}
if (beg[tot]==a[d[1]])	tot--;
for (int i=1;i<=top;i++)
	beg[++tot]=a[d[i]];
}

int kake(){
int now=3,ans=0;
for (int i=1;i<=tot;i++)
	{
		while (cross(beg[i+1]-beg[i],beg[now+1]-beg[i])>cross(beg[i+1]-beg[i],beg[now]-beg[i]))
			{
				now++;
				if (now>tot)	now=1;
			}
		ans=max(ans,max(dist(beg[i],beg[now]),dist(beg[i+1],beg[now+1])));
	}
return ans;
}

int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++)
	scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+n+1,cmp);
doit(1);
doit(-1);
if (beg[tot]==beg[1])
	tot--;
beg[tot+1]=beg[1];
printf("%d\n",kake());
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值