ZOJ problem Set-3664 Split the Rectangle

Source: Internet
Author: User

The ACM-ICPC Asia Changchun regional contest-j


The title of a freshman is to remove some of the two points in the same rectangle, and then ask how many rectangles are left.


Actually is can make a binary tree, the process of formation is the process of separating the rectangle. Then the answer is clearly the number of leaf nodes---A and B LCA is the root of the subtree of the number of leaf nodes +1.

#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #define MAXN usi
NG namespace Std;
        struct rect{int x1,x2,y1,y2;
int l,r,soncnt;
}R[MAXN]; struct segment{int x1,x2,y1,y2;}
P[MAXN]; struct point{int x, y;}
b;
int N,q,tot; BOOL Innerline (int v,int l,int R) {return (v>=l && v<=r);} int Buildtree (Rect node, int fl
        AG) {R[tot]=node;
        R[tot].l=r[tot].r=-1;
        r[tot].soncnt=0;
        int res = tot++; for (int i=0;i<n;++i) if ((p[i].y1==p[i].y2) ^flag) {if (!flag) {if (p[i].x1==node.x 1 && p[i].x2==node.x2 && innerline (p[i].y1,node.y1,node.y2)) {Rect Te
                    MP = node;
                    Temp.y1=p[i].y1;
                    
                    R[res].l= Buildtree (Temp,!flag);
                    temp = node;
            Temp.y2=p[i].y2;        R[res].r= Buildtree (Temp,!flag); }} else {if (p[i].y1==node.y1 && p[i].y2==node.y2 && innerline (p[
                    I].X1,NODE.X1,NODE.X2)) {Rect temp = node;
                    temp.x1=p[i].x1;
                    
                    R[res].l= Buildtree (Temp,!flag);
                    temp= node;
                    temp.x2=p[i].x2;
                 R[res].r= Buildtree (Temp,!flag);
            }}} if (R[res].l==-1 && r[res].r==-1) R[res].soncnt=1;else {
            if (r[res].l!=-1) r[res].soncnt=r[r[res].l].soncnt;
        if (r[res].r!=-1) r[res].soncnt+=r[r[res].r].soncnt;
} return res; } bool Innerrect (point C,rect R) {return (c.x>=r.x1 && c.x<=r.x2 && c.y>=r.y1 &&am P
C.Y&LT;=R.Y2); } int DFS (Rect node) {if (node.l!=-1) {if (Innerrect (A, R[NODE.L]) && innerrect (B,R[NODE.L])) return DFS (R[NODE.L]);  } if (Node.r!=-1) {if (Innerrect (A,R[NODE.R]) && innerrect (B,R[NODE.R])) return
        DFS (R[NODE.R]);
} return node.soncnt; } int main () {while (cin>>r[0].x1>>r[0].y1>>r[0].x2>>r[0].y2) {cin>>n>>
          Q;
              for (int i=0;i<n;++i) {scanf ("%d%d%d%d", &p[i].x1,&p[i].y1,&p[i].x2,&p[i].y2);
              if (p[i].x1>p[i].x2) swap (P[I].X1,P[I].X2);
          if (p[i].y1>p[i].y2) swap (P[I].Y1,P[I].Y2);
          } tot=0;
          Buildtree (r[0],0);
              for (int i=0;i<q;++i) {scanf ("%d%d%d%d", &a.x,&a.y,&b.x,&b.y);
          Cout<<n+2-dfs (r[0]) <<endl;
}} return 0; }



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.