求平面最大点对。
找凸包 -> 根据凸包运用旋转卡壳算法求最大点对(套用kuang巨模板)
#include<bits/stdc++.h> using namespace std; struct point { int x,y; point operator -(const point& rhs)const { point ret; ret.x=x-rhs.x; ret.y=y-rhs.y; return ret; } int operator *(const point& rhs)const//叉乘 { return x*rhs.y-y*rhs.x; } bool operator <(const point& rhs)const { return x<rhs.x||x==rhs.x&&y<rhs.y; } } p[],s[]; int top; bool ok(point A,point B,point C) //判断ABC是否是按逆时针顺序给出 { ; } int dist2(point a,point b) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); } int rotating_calipers() { ; point v; ; ; i < top; i++) { v = s[i]-s[(i+)%top]; )%top]-s[cur])) < ) cur = (cur+)%top; ret = max(ret,max(dist2(s[i],s[cur]),dist2(s[(i+)%top],s[(cur+)%top]))); } return ret; } int main() { int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); ; i<n; i++) scanf("%d%d",&p[i].x,&p[i].y); sort(p,p+n); top=; ; i<n; i++) //求下凸包 { && !ok(s[top-],s[top-],p[i])) top--; s[top++]=p[i]; } ; ; i>=; i--) //求上凸包 { && !ok(s[top-],s[top-],p[i])) top--; s[top++]=p[i]; } --top; // 首尾点相同,故舍去 int ans=rotating_calipers(); printf("%d\n",ans); } }