题目大意:求平面上点集中的最远点对间距离的平方
第一次写旋转卡壳- - 能1A真是开心- -
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 50500
#define EPS 1e-7
#define INF 1e8
using namespace std;
struct Point{
int x,y;
friend istream& operator >> (istream &is,Point &p)
{
scanf("%d%d",&p.x,&p.y);
return is;
}
bool operator < (const Point &p) const
{
if(x==p.x)
return y<p.y;
return x<p.x;
}
friend double Get_Slope(const Point &p1,const Point &p2)
{
if(p1.x==p2.x)
return p1.y<p2.y?INF:-INF;
return (double)(p1.y-p2.y)/(p1.x-p2.x);
}
friend int Distance(const Point &p1,const Point &p2)
{
return (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y);
}
}points[M];
int n,ans;
Point *stack1[M],*stack2[M];
int top1,top2;
//stack1 上凸包
//stack2 下凸包
void Get_Convex_Hull()
{
int i;
{
Point **stack=stack1;
int &top=top1;
for(i=1;i<=n;i++)
{
while( top>=2 && Get_Slope(*stack[top-1],*stack[top])<Get_Slope(*stack[top],points[i])+EPS )
stack[top--]=0x0;
stack[++top]=&points[i];
}
}
{
Point **stack=stack2;
int &top=top2;
for(i=1;i<=n;i++)
{
while( top>=2 && Get_Slope(*stack[top-1],*stack[top])>Get_Slope(*stack[top],points[i])-EPS )
stack[top--]=0x0;
stack[++top]=&points[i];
}
}
}
void Rotating_Calipers()
{
int i,j;
for(j=top2,i=1;i<=top1;i++)
{
double slope=(i==top1?-INF:Get_Slope(*stack1[i],*stack1[i+1]) );
ans=max(ans,Distance(*stack1[i],*stack2[j]) );
while( j>1 && Get_Slope(*stack2[j-1],*stack2[j])>slope )
j--,ans=max(ans,Distance(*stack1[i],*stack2[j]) );
}
}
int main()
{
int i;
cin>>n;
for(i=1;i<=n;i++)
cin>>points[i];
sort(points+1,points+n+1);
Get_Convex_Hull();
Rotating_Calipers();
cout<<ans<<endl;
return 0;
}