#P2449. [SDOI2005] 矩形
[SDOI2005] 矩形
Description
We have drawn rectangles on a plane. Each rectangle has its sides parallel to the coordinate axes, and all vertex coordinates are integers. We define a shape that satisfies the following properties to be a block:
-
Each rectangle is a block.
-
If two blocks have a segment of overlap, then these two blocks form a new block; otherwise, the two blocks are different.
Example:
In Figure , the rectangles form two different blocks. In Figure , the rectangles form one block.

Task:
Please write a program to:
- Read the vertex coordinates of each rectangle from standard input.
- Find the number of different blocks among these rectangles.
- Output the result to standard output.
Input Format
The first line contains an integer , where , the number of rectangles. Each of the next lines gives the vertex coordinates of a rectangle. Each rectangle is described by four integers: the -coordinate of the lower-left corner, the -coordinate of the lower-left corner, the -coordinate of the upper-right corner, and the -coordinate of the upper-right corner. All coordinates are non-negative integers not greater than .
Output Format
Output a single integer — the number of different blocks formed by these rectangles.
9
0 3 2 6
4 5 5 7
4 2 6 4
2 0 3 2
5 3 6 4
3 2 5 3
1 4 4 7
0 0 1 4
0 0 4 1
2
Hint

The thick orange segments indicate where overlaps occur. The number in the center of each square denotes the ID of the block it belongs to.
Note: Corner touching does not count as the same block.
Translated by ChatGPT 5
京公网安备 11011102002149号