Given n vertices, cover all vertices with three sides with the same length. The square boundary must be perpendicular to the coordinate axis, and the minimum value of the square side length must be obtained.
The maximum value is the smallest, which is obviously a binary answer.
But verification is a problem.
Considering that there are only three squares, the conclusion is not true if a minimum rectangle is used to cover these three squares.
So we use DFS to overwrite all vertices with the smallest rectangle each time, and fill in the square with the four corners of the enumerated rectangle.
Since the maximum depth is 3, the time is completely tolerable.
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define M 20100using namespace std;struct abcd{int x,y;}points[M];int n,v[M];int stack[M],top;bool DFS(int L,int dpt){int i,j,bottom=top;int minx=0x3f3f3f3f,maxx=0xefefefef;int miny=0x3f3f3f3f,maxy=0xefefefef;if(top==n)return true;if(dpt==3)return false;for(i=1;i<=n;i++)if(!v[i]){minx=min(minx,points[i].x);maxx=max(maxx,points[i].x);miny=min(miny,points[i].y);maxy=max(maxy,points[i].y);}int dx[]={minx,minx,maxx-L,maxx-L};int dy[]={miny,maxy-L,miny,maxy-L};for(j=0;j<4;j++){for(i=1;i<=n;i++)if(!v[i])if(points[i].x>=dx[j]&&points[i].x<=dx[j]+L)if(points[i].y>=dy[j]&&points[i].y<=dy[j]+L)v[i]=1,stack[++top]=i;bool flag=DFS(L,dpt+1);while(top!=bottom)v[stack[top--]]=0;if(flag)return true;}return false;}int Bisection(){int l=0,r=0x3f3f3f3f;while(l+1<r){int mid=l+r>>1;if( DFS(mid,0) )r=mid;elsel=mid;}if( DFS(l,0) )return l;return r;}int main(){int i;cin>>n;for(i=1;i<=n;i++)scanf("%d%d",&points[i].x,&points[i].y);cout<<Bisection()<<endl;}
Bzoj 1052 haoi2007 covers problem dual answers + DFS