A :: Rectangular Rectitude
Time Limit: 5 Seconds Memory Limit: 32768 KB
Starting with an initial colorless background, we will paint a sequence of potentially overlapping, horizontally-aligned rectangles of various colors. The problem is to determine the exposed area of a given color.
Input
The input data file contains a collection of independent datasets.
The first line of each dataset contains two numbers. The first number is an
integer 0 <= n <= 1000 specifying the number of rectangles that follow.
The second number is a positive integer 0 < c < 8, representing the color
whose exposed area we want to determine.
Each of the next n lines of the dataset contains information about a rectangle, and the lines are given in order of the painting sequence. The first number on the line is an integer 0 < c' < 8, representing the rectangle's color. The next two integer values on the line are respectively the x- and y-coordinates of any corner of the rectangle. The last two integer values are respectively the x- and y-coordinates of the diagonally opposite corner of the rectangle. All coordinates lie in the range from -100 to +100 inclusively.
The end of input will be indicated by a dataset with n = 0. This dataset should not be processed.
Output
For each dataset, the output of your program will be a single line containing the string "The area of color x in dataset y is: " followed by a single integer representing the area (in square units) of the exposed color specified in the dataset.
Sample Input
4 2 2 6 0 0 4 4 1 -4 3 -1 2 3 3 8 7 5 2 -2 4 6 1 5 7 0 0 1 1 2 3 3 0 0 2 2 4 0 0 1 1 0 1
Sample Output
The area of color 2 in dataset 1 is: 31 The area of color 5 in dataset 2 is: 0 The area of color 3 in dataset 3 is: 3Submit
Source: Southeast USA 2000