Float: calculates the area of the color from the top rectangle to the bottom rectangle. For each rectangle, it is raised from its position. When it encounters the rectangle above it, it is split into several small rectangles to simulate the floating process recursively.
It seems that a question in Asia is similar to this one in a year. The rectangle on the screen is covered, but that question has a maximum of 26 rectangles, which can be solved by brute force. This is simpler than this.
01 /*
02 ID: jzzlee1
03 PROB: rect1
04 LANG: C ++
05 */
06 // # include <iostream>
07 # include <fstream>
08 using namespace std;
09 ifstream cin ("rect1.in ");
10 ofstream cout ("rect1.out ");
11 long int x1 [1010], y1 [1010], x2 [1010], y2 [1010], ans [2510], c [2510];
12 int n, maxc;
13 void color (int l, int r, int s, int d, int k, int col)
14 {
15 while (k <= n) & (l> = x2 [k]) | (r <= x1 [k]) | (d <= y1 [k]) | s> = y2 [k])
16 k ++;
17 if (k> n)
18 {
19 ans [col] + = (r-l) * (d-s );
20 return;
21}
22 else
23 {
24 if (l <= x1 [k])
25 {
26 color (l, x1 [k], s, d, k + 1, col );
27 l = x1 [k];
28}
29 if (r> = x2 [k])
30 {
31 color (x2 [k], r, s, d, k + 1, col );
32 r = x2 [k];
33}
34 if (s <= y1 [k])
35 {
36 color (l, r, s, y1 [k], k + 1, col );
37 s = y1 [k];
38
39}
40 if (d> = y2 [k])
41 {
42 color (l, r, y2 [k], d, k + 1, col );
43 d = y2 [k];
44}
45}
46}
47 void work ()
48 {
49 int I, j;
50 cin> x2 [0]> y2 [0]> n;
51x1 [0] = 0;
52 y1 [0] = 0;
53 c [0] = 1;
54 maxc = 0;
55 for (I = 1; I <= n; I ++)
56 {
57 cin> x1 [I]> y1 [I]> x2 [I]> y2 [I]> c [I];
58 if (c [I]> maxc)
59 maxc = c [I];
60}
61 for (I = n; I> = 0; I --)
62 color (x1 [I], x2 [I], y1 [I], y2 [I], I + 1, c [I]);
63 for (I = 1; I <= maxc; I ++)
64 if (ans [I]! = 0)
65 cout <I <"" <ans [I] <endl;
66}
67 int main () www.2cto.com
68 {
69 work ();
70 return 0;
71}