cogs103&tyvj1899 [NOIP2002] Rectangle Overlay

Source: Internet
Author: User

The scope of the topic is k<=4, but the official data is not k==4, resulting in some weird DP writing can also be passed. I heard that the calibration process in the k==4 when there are counter-examples, lift table ..... No wonder the answer to K==4 's data on cogs is wrong.

Well, write a search: There are a lot of writing on the Web. I'm going to split the set of points into two parts along a straight line parallel to the axis, and enumerate how K-rectangles are allocated on both sides. The boundary is k==1, sweep over all points to find the smallest rectangle. See the code for details.

But I cannot guarantee that this search is right because k==4 is likely to have this rugged and optimal solution: there is no line parallel to the axis and does not intersect any of the rectangles to divide the 4 rectangles into two parts. For example, the optimal scheme is:

Put a code: recursion in order to deal with "the point set divided into two parts" tuned a bunch of memcpy .... Fortunately, the number of recursive layers and points are not many, or the constant bombing days ....

#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intmaxn= -;intX[maxn],y[maxn],seq[maxn];inlineintMaxintAintb) {    returnA>b?a:b;} InlineintMinintAintb) {    returnA<b?a:b;}BOOLCMP1 (Const int&a,Const int&b) {    returnx[a]<x[b];}BOOLCMP2 (Const int&a,Const int&b) {    returny[a]<y[b];}structnode{intX1,y1,x2,y2; Node () {} node (intAintBintCintd) {X1=a;y1=b;x2=c;y2=D; }}sol[Ten];intCnt=0;intWorkintLintRintseq[]) {    intminx=0x7f7f7f7f, miny=0x7f7f7f7f, maxx=0, maxy=0;  for(intI=l;i<=r;++i) {//printf ("seq%d\n", Seq[i]);Minx=min (Minx,x[seq[i]); maxx=Max (Maxx,x[seq[i]]); Miny=min (Miny,y[seq[i]); maxy=Max (Maxy,y[seq[i]]); } sol[++cnt]=node (minx,miny,maxx,maxy); return(Maxx-minx) * (maxy-miny);}ints[ +][ -];inttot=0;intDfsintLintRintKintSeq[]) {//printf ("%d\n", k);    if(k==1){        inttmp=Work (L,R,SEQ); CNT--; returntmp; }Else{        intans=0x7f7f7f7f; Sort (Seq+l,seq+r+1, CMP1);  for(inti=l;i<r;++i) {             for(intj=1; j<k;++j) {                ++tot; memcpy (S[tot],seq,sizeof(int)* -); ++tot; memcpy (S[tot],seq,sizeof(int)* -); if(x[seq[i]]!=x[seq[i+1]]){                    intTmp=dfs (l,i,j,s[tot-1]) +dfs (i+1, r,k-J,s[tot]); Ans=min (ans,tmp); }                --tot;--tot; //printf ("---------------\ n");            }        }//printf ("%d\n", ans);Sort (seq+l,seq+r+1, CMP2);  for(inti=l;i<r;++i) {             for(intj=1; j<k;++j) {                ++tot; memcpy (S[tot],seq,sizeof(int)* -); ++tot; memcpy (S[tot],seq,sizeof(int)* -); if(y[seq[i]]!=y[seq[i+1]]){                    intTmp=dfs (l,i,j,s[tot-1]) +dfs (i+1, r,k-J,s[tot]); Ans=min (ans,tmp); }                --tot;--tot; //printf ("---------------\ n");            }        }//printf ("%d\n", ans);        returnans; }}intMain () {intn,k; scanf ("%d%d",&n,&k);  for(intI=1; i<=n;++i) {scanf ("%d%d", x+i,y+i); }     for(intI=1; i<=n;++i) {Seq[i]=i; } printf ("%d\n", DFS (1, N,k,seq)); return 0;}

cogs103&tyvj1899 [NOIP2002] Rectangle Overlay

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.