传送门: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());
}