Hdu2461 Rectangles ----- reject

Source: Internet
Author: User

Rectangles
Time Limit: 5000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 989 Accepted Submission (s): 558


Problem Description
You are developing a software for painting rectangles on the screen. the software supports drawing several rectangles and filling some of them with a color different from the color of the background. you are to implement an important function. the function answer such queries as what is the colored area if a subset of rectangles on the screen are filled.

Input
The input consists of multiple test cases. each test case starts with a line containing two integers N (1 ≤ N ≤ 20) and M (1 ≤m ≤ 100000 ), indicating the number of rectangles on the screen and the number of queries, respectively.
The I-th line of the following N lines contains four integers X1, Y1, X2, Y2 (0 ≤ X1 <X2 ≤1000, 0 ≤ Y1 <Y2 ≤ 1000 ), which indicate that the lower-left and upper-right coordinates of the I-th rectangle are (X1, Y1) and (X2, Y2 ). rectangles are numbered from 1 to N.
The last M lines of each test case describe M queries. each query starts with a integer R (1 <= R ≤ N), which is the number of rectangles the query is supposed to fill. the following list of R integers in the same line gives the rectangles the query is supposed to fill, each integer of which will be between 1 and N, inclusive.

The last test case is followed by a line containing two zeros.

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

Sample Input
2 2
0 0 2 2
1 1 3 3
1 1
2 1 2
2 1
0 1 1 2
2 1 3 2
2 1 2
0 0

Sample Output
Case 1:
Query 1: 4
Query 2: 7

Case 2:
Query 1: 2

Source
2008 Asia Hefei Regional Contest Online by USTC

Recommend
Teddy
Question: give n rectangles, then apply m rectangles each time, and ask how much area the colored area is.
You can use the refresh principle.
[Cpp]
# Include <iostream>
# Include <cstdlib>
# Include <stdio. h>
# Include <algorithm>
Using namespace std;
Int n, m, num, res;
Int a [25];
Struct Node
{
Int x1, y1, x2, y2;
Int s;
} Node [25];
Bool check (Node x, int u)
{
If (node [u]. x1> = x. x2) return 0;
If (x. x1> = node [u]. x2) return 0;
If (node [u]. y1> = x. y2) return 0;
If (x. y1> = node [u]. y2) return 0;
Return 1;
}
Void solve (Node rec, int id, int k)
{
Node temp;
If (id = num + 1) return;
For (int I = id; I <= num; I ++)
{
If (check (rec, a [I])
{
Temp. x1 = rec. x1> node [a [I]. x1? Rec. x1: node [a [I]. x1;
Temp. y1 = rec. y1> node [a [I]. y1? Rec. y1: node [a [I]. y1;
Temp. x2 = rec. x2 <node [a [I]. x2? Rec. x2: node [a [I]. x2;
Temp. y2 = rec. y2 <node [a [I]. y2? Rec. y2: node [a [I]. y2;
Temp. s = (temp. x2-temp.x1) * (temp. y2-temp.y1 );
If (k % 2) res + = temp. s;
Else res-= temp. s;
Solve (temp, I + 1, k + 1 );
}
}
}
Int main ()
{
Int count = 1;
While (scanf ("% d", & n, & m )! = EOF)
{
If (n = 0 & m = 0) break;
For (int I = 1; I <= n; I ++)
{
Scanf ("% d", & node [I]. x1, & node [I]. y1, & node [I]. x2, & node [I]. y2 );
Node [I]. s = (node [I]. x2-node [I]. x1) * (node [I]. y2-node [I]. y1 );
}
Printf ("Case % d: \ n", count ++ );
For (int I = 1; I <= m; I ++)
{
Scanf ("% d", & num );
Res = 0;
For (int j = 1; j <= num; j ++)
{
Scanf ("% d", & a [j]);
Res + = node [a [j]. s;
}
For (int j = 1; j <= num; j ++)
{
Solve (node [a [j], j +, 0 );
}
Printf ("Query % d:", I );
Printf ("% d \ n", res );
}
Puts ("");
}
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.