Poj 3695-rectangles Rectangular Cut

Source: Internet
Author: User

Rectangles
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 3846 Accepted: 1124

Description

You is developing a software for painting rectangles in the screen. The software supports drawing several rectangles and filling some of them with a color different from the color of the BAC Kground. You is to implement an important function. The function answer such queries as what's the colored area if a subset of rectangles in the screen is filled.

Input

The input consists of multiple test cases. Each test case starts with a line containing the integersN(1≤N≤20) andM(1≤M≤100000), indicating the number of rectangles on the screen and the number of queries, respectively.
TheI-th Line of the followingNLines contains four integersX1,Y1,X2,Y2 (0≤X1 <X2≤1000, 0≤y1 < y2≤1000), which indicate that the lower-left and upper-right coordinates of theI-th Rectangle is (X1,Y1) and (X2,Y2). Rectangles is numbered from 1 toN.
The lastMLines of each test case describeMQueries. Each query starts with a integerR(1<=RN), which is the number of rectangles the query was supposed to fill. The following list ofRIntegers in the same line gives the rectangles the query was supposed to fill with each integer of which would be between 1 andN, inclusive.

The last test was followed by a line containing the zeros.

Output

For each test case, print a line containing the test case number (beginning with 1).
For each query of the input, print a line containing the query number (beginning with 1) followed by the corresponding ANS Wer for the query. Print a blank line after the output for each test case.

Sample Input

2  20 0 2 21 1 3 31 12 1 22 10 1 1 22 1 3 22 1 20 0

Sample Output

Case 1:query 1:4query 2:7case 2:query 1:2

Source

Asia Hefei Regional Contest Online by USTC

Test instructions: Give you some rectangles, numbered 1~n. There are some queries, each asking you some of the rectangular area and.

Exercises

Rectangular Cutting

Rectangular Cut bare title ... Of course you can also use the line segment tree (Tai Hang ... )

Just hanging a template is over.

It was said that the rectangular cut would be tle in discuss. It may be that the constant is too big. But I do not have tle ah, and seems to run fast (time seems to row 32, memory is very small ...) )

1#include <bits/stdc++.h>2 using namespacestd;3 structnode4 {5     intX1,y1,x2,y2;6}r[ -];7 ints1,cc[ -],ans[ -];8 intRead ()9 {Ten     ints=0, fh=1;CharCh=GetChar (); One      while(ch<'0'|| Ch>'9'){if(ch=='-') fh=-1; ch=GetChar ();} A      while(ch>='0'&&ch<='9') {s=s*Ten+ (ch-'0'); ch=GetChar ();} -     returns*fh; - } the voidCover (intX1,intY1,intX2,intY2,intKintK1) - { -      while(k<=s1&& (X1>=r[cc[k]). x2| | X2<=r[cc[k]]. x1| | Y1>=r[cc[k]]. y2| | Y2<=r[cc[k]]. Y1)) k++; -     if(k>=s1+1) {ans[k1]+= (x2-x1) * (Y2-Y1);return;} +     if(X1<r[cc[k]]. X1) {Cover (X1,y1,r[cc[k]). x1,y2,k+1, K1); x1=R[cc[k]]. X1;} -     if(X2>r[cc[k]]. X2) {Cover (R[cc[k]). x2,y1,x2,y2,k+1, K1); X2=R[cc[k]]. X2;} +     if(Y1<r[cc[k]]. Y1) {Cover (X1,y1,x2,r[cc[k]). y1,k+1, K1); y1=R[cc[k]]. Y1;} A     if(Y2>r[cc[k]]. Y2) {Cover (X1,r[cc[k]). y2,x2,y2,k+1, K1); Y2=R[cc[k]]. Y2;} at } - intMain () - { -     intn,m,i,case1=0, c=0, J,sum; -      while(1) -     { inN=read (); M=read ();if(n==0&&m==0) Break; -          for(i=1; i<=n;i++) {r[i]. X1=read (); R[i]. Y1=read (); R[i]. X2=read (); R[i]. Y2=read ();} toprintf"Case %d:\n",++case1); +C=0; -          for(i=1; i<=m;i++) the         { *s1=read (); $              for(j=1; j<=s1;j++) cc[j]=read ();Panax Notoginseng              for(j=s1;j>=1; j--) Cover (R[cc[j]]. X1,R[CC[J]]. Y1,R[CC[J]]. X2,R[CC[J]]. y2,j+1, j);//Rectangular Cutting Method -sum=0; the              for(j=1; j<=s1;j++) {sum+=ans[j];ans[j]=0;} +printf"Query%d:%d\n",++c,sum); A         } theprintf"\ n"); +     } - fclose (stdin); $ fclose (stdout); $     return 0; -}

Poj 3695-rectangles Rectangular Cut

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.