The area of the rectangle is the same.
Question: rectangular cutting.
[Cpp]
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Include <string>
# Include <queue>
# Include <algorithm>
# Include <vector>
# Include <stack>
# Include <list>
# Include <iostream>
# Include <map>
# Include <math. h>
Using namespace std;
# Define inf 0x3f3f3f
# Define uint unsigned _ int64
# Define M 10000
Struct node
{
Double p1 [2], p2 [2];
} A [M], now;
Int total;
Int judge (node a, node B)
{
For (int I = 0; I <2; I ++)
{
If (a. p2 [I] <= B. p1 [I] | a. p1 [I]> = B. p2 [I])
Return 0;
}
Return 1;
}
Void cut (node tmp)
{
Int k1, k2;
For (int I = 0; I <2; I ++)
{
K1 = max (tmp. p1 [I], now. p1 [I]);
K2 = min (tmp. p2 [I], now. p2 [I]);
If (tmp. p1 [I] <k1)
{
A [++ total] = tmp;
A [total]. p2 [I] = k1;
}
If (tmp. p2 [I]> k2)
{
A [++ total] = tmp;
A [total]. p1 [I] = k2;
}
Tmp. p1 [I] = k1;
Tmp. p2 [I] = k2;
}
}
Int main ()
{
Int n, I, j, count = 1;
While (scanf ("% d", & n), n)
{
Total = 0;
For (I = 1; I <= n; I ++)
{
Scanf ("% lf", & now. p1 [0], & now. p1 [1], & now. p2 [0], & now. p2 [1]);
For (j = total; j> = 1; j --)
{
If (judge (now, a [j])
{
Cut (a [j]);
A [j] = a [total --];
}
}
A [++ total] = now;
}
Double sum = 0.0;
For (I = 1; I <= total; I ++)
Sum + = (a [I]. p2 [0]-a [I]. p1 [0]) * (a [I]. p2 [1]-a [I]. p1 [1]);
Printf ("Test case # % d \ n", count ++ );
Printf ("Total received area: %. 2lf \ n", sum );
Puts ("");
}
}