Beauty Contest POJ - 2187 

题意 : 求凸包上距离最远的两个点,普通做法O(n^2),旋转卡壳O(n);

关于旋转卡壳的总结 , 传送门​​​​​​​

#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=3e5+5;
const int MOD=1e9+7;
template <class T>
bool sf(T &ret){ //Faster Input
    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}
int sign(int x){
    return abs(x)<1e-7?0:x<0?-1:1;
}
struct Point{
    ll x,y;
    Point(ll x=0.0, ll y=0.0) : x(x), y(y) {}
    Point operator - (const Point &rhs) const{
        return Point(x-rhs.x,y-rhs.y);
    }
    bool operator == (const Point &rhs) const{
        return sign(x-rhs.x)==0&&sign(y-rhs.y)==0;
    }
    bool operator < (const Point &rhs)const{
        if(x==rhs.x)    return y<rhs.y;
        else    return x<rhs.x;
    }
}p[N];
typedef Point Vector;
ll cross(Vector A,Vector B){
    return A.x*B.y-A.y*B.x;
}
int n;
typedef vector<Point> Polygon;
Polygon convex_hull(Polygon P){
    sort(P.begin(),P.end());
    P.erase(unique(P.begin(), P.end()), P.end());
    int n=P.size(),k=0;
    Polygon Q(n*2);
    for(int i=0;i<n;++i){
        while(k>1&&cross(Q[k-2]-Q[k-1],Q[k-2]-P[i])<=0) k--;
            Q[k++]=P[i];
    }
    int t=k;
    for(int i=n-2;i>=0;--i){
        while(k>t && cross(Q[k-2]-Q[k-1],Q[k-2]-P[i])<=0)   k--;
        Q[k++]=P[i];
    }
    Q.resize(k-1);
    return Q;
}

ll dis(Point a,Point b){
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

ll query(Polygon t){
    int sz=(int)t.size();
    if(sz==0||sz==1)  return 0;
    if(sz==2)    return dis(t[0],t[1]);
    ll res=0;
    t.pb(t[0]);
    ++sz;
    int j=2;
    for(int i=0;i<sz-1;++i){ /// 枚举所有边
        while(cross(t[i+1]-t[i],t[j]-t[i])<cross(t[i+1]-t[i],t[j+1]-t[i]))  ++j,j%=(sz-1); //注意j取模
        res=max(res,max(dis(t[j],t[i]),dis(t[j],t[i+1])));
    }
    return res;
}
bool cmp(Point a, Point b)  {
    return cross (a, b) > 0;
}
int main(void){
    int n;
    while(scanf("%d",&n)==1){
        Polygon t;
        for(int i=1;i<=n;i++)   scanf("%lld%lld",&p[i].x,&p[i].y);
        for(int i=1;i<=n;i++)   t.pb(p[i]);
//        sort(t.begin(),t.end(),cmp);
        t=convex_hull(t);
        printf("%lld\n",query(t));
    }
}