Bzoj 1052 haoi2007 covers problem dual answers + DFS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.