题目大意:给定平面上n个点,求最远的两个点的距离的平方。
旋转卡壳裸题,第一次写旋转卡壳,好鸡冻,得到的教训是斜率一定要注意INF和-INF的区别。顺便说一下旋转卡壳的做法,我们先求出一个凸包,然后在上凸壳和下凸壳一块扫,先让上凸壳跑到下一条线,再看下凸壳是否也应该跑到下一条线(感觉表达力吃鸡),总之扫一遍就好了,然后对于每个卡到的点对求一边距离的平方,就完事了。
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
#define INF 1e8
#define eps 1e-8
struct point
{
int x,y;
point(){}
point(double _,double __):x(_),y(__){}
double operator ^ (point b)
{
if(x==b.x) return (y<b.y?INF:-INF);
return (double)(b.y-y)/(b.x-x);
}
bool operator < (point b) const
{
if(x==b.x) return y<b.y;
return x<b.x;
}
int operator & (point b)
{
return (b.x-x)*(b.x-x)+(b.y-y)*(b.y-y);
}
}points[100000];
point up[100000];
point down[100000];
int top1,top2;
int tot;
void get_hull()
{
sort(points+1,points+1+tot);
for(int i=1;i<=tot;i++)
{
while(top1>=2 && (up[top1-1]^up[top1])<(up[top1]^points[i])) top1--;
up[++top1]=points[i];
}
for(int i=1;i<=tot;i++)
{
while(top2>=2 && (down[top2-1]^down[top2])>(down[top2]^points[i])) top2--;
down[++top2]=points[i];
}
}
int ans=0;
void rot()
{
for(int i=1,j=top2;i<=top1;i++)
{
double slope1=(i==top1 ? -INF : up[i]^up[i+1]);
ans=max(ans,up[i]&down[j]);
while(j>1 && (down[j-1]^down[j])>slope1)
{
j--;
ans=max(ans,up[i]&down[j]);
}
}
}
int main()
{
int n;
scanf("%d",&n);
tot=n;
for(int i=1;i<=n;i++) scanf("%d%d",&points[i].x,&points[i].y);
get_hull();
rot();
cout<<ans;
return 0;
}