简单的旋转卡壳题目
以每一条边作为基础,找到那个最远的对踵点,计算所有对踵点的点对距离
这里求的是距离的平方,所有过程都是int即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 50010
#define eps 1e-9
int n , top; int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
} struct Point{
int x,y;
Point(int x= , int y=):x(x),y(y){}
bool operator==(const Point &m) const{
return x==m.x&&y==m.y;
}
int squaredDis(){return x*x+y*y;}
void input(){scanf("%d%d" , &x , &y);}
void print(){cout<<x<<" "<<y<<endl;}
}po[N] , rec[N] , p;
typedef Point Vector; Vector operator+(Vector a , Vector b){return Vector(a.x+b.x , a.y+b.y);}
Vector operator-(Vector a , Vector b){return Vector(a.x-b.x , a.y-b.y);}
Vector operator*(Vector a , double b){return Vector(a.x*b , a.y*b);}
Vector operator/(Vector a , double b){return Vector(a.x/b , a.y/b);} int Cross(Vector a , Vector b){return a.x*b.y-b.x*a.y;}
double Len(Vector a){return sqrt(a.x*a.x*1.0+a.y*a.y);} bool cmp(Point a , Point b){
int v = Cross(a , b);
if(v == ) return a.x<b.x;
else return v>;
} void Graham(Point *a , Point *rec)
{
sort(a , a+n , cmp);
// for(int i=0 ; i<n ; i++) cout<<i<<" "<<a[i].x<< " "<<a[i].y<<endl;
rec[] = a[] , rec[] = a[];
top=;
for(int i= ; i<n ; i++){
while(top> && Cross(rec[top]-rec[top-] , a[i]-rec[top-])<=)
top--;
rec[++top] = a[i];
}
// for(int i=0 ; i<=top ; i++) cout<<i<<" "<<rec[i].x<< " "<<rec[i].y<<endl;
int tmp = top;
for(int i=n- ; i>= ; i--){
while(top>tmp && Cross(rec[top]-rec[top-] , a[i]-rec[top-])<=)
top--;
rec[++top]=a[i];
}
// for(int i=0 ; i<=top ; i++) cout<<i<<" "<<rec[i].x<< " "<<rec[i].y<<endl;
} int maxDis(Point *a)
{
int la=top- , p= , q=;
int maxn = ;
for(p= ; p<top ; p++){
while(Cross(a[p]-a[la] , a[q+]-a[la]) - Cross(a[p]-a[la] , a[q]-a[la])>)
q=(q+)%top;
maxn = max(maxn , (a[q]-a[la]).squaredDis());
maxn = max(maxn , (a[q]-a[p]).squaredDis());
la = p;
}
return maxn;
} int main()
{
// freopen("a.in" , "r" , stdin);
while(~scanf("%d" , &n))
{
for(int i= ; i<n ; i++) po[i].input();
p = po[];
for(int i= ;i<n ; i++)
if(po[i].y<p.y||(po[i].y==p.y&&po[i].x<p.x)) p=po[i];
Graham(po , rec);
int ans = maxDis(rec);
cout<<ans<<endl;
}
return ;
}