Given N (n≤1500) points, the maximum area of four points as the vertices of the rectangle is chosen to ensure the solution.
For every two points, the edges are sorted by length, the edges with the same midpoint are enumerated as a diagonal rectangle, and the area is calculated as the maximum value.
Time complexity O (N2LOGN)
#include <cstdio>#include<algorithm>intxs[ the],ys[ the];Long Longans=0;structedge{intX1,y1,x2,y2; Long LongLen; intXm,ym; voidcal () {XM=x1+x2,ym=y1+Y2; intX=x1-x2,y=y1-Y2; Len=x*1ll*x+y*1ll*y; }}es[2250005];inlineBOOL operator<(Edge A,edge b) {if(A.len<b.len)return 1; Else if(a.len==B.len) { if(A.XM<B.XM)return 1; Else if(A.XM==B.XM)returna.ym<B.ym; Else return 0; } Else return 0;} InlineLong LongCal (edge&a,edge&b) { Long Longx= (a.x1-b.x1) *1ll* (a.y1-b.y2)-(A.X1-B.X2) *1ll* (a.y1-b.y1); returnx<0?-x:x;}intp=0, N;intMain () {scanf ("%d",&N); for(intI=0; i<n;i++) scanf ("%d%d", xs+i,ys+i); for(intI=0; i<n;i++) for(intj=i+1; j<n;j++) {Edge&e=es[p++]; E.x1=xs[i],e.y1=Ys[i]; E.x2=xs[j],e.y2=Ys[j]; E.cal (); } std::sort (Es,es+p); for(intI=0; i<p;i++){ for(intj=i+1; j<p&&es[i].len==es[j].len&&es[i].xm==es[j].xm&&es[i].ym==es[j].ym;j++){ Long Longs=Cal (Es[i],es[j]); if(S>ans) ans=s; }} printf ("%lld", ans); return 0;}
bzoj2338 Number Rectangle