1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
| #include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps = 1e-9;
class Line
{
public:
double left, right, y;
bool ToDelete;
Line(const double _left = .0, const double _right = .0, const double _y = .0, const bool _ToDelete = false):
left(_left), right(_right), y(_y), ToDelete(_ToDelete) { }
bool operator< (const Line& rhs) const
{
return y < rhs.y;
}
} line[202];
struct SegmentTree
{
double length;
int count;
} s[202*8];
int n, T, ny, nl, nx, st ,ed, x;
double yy[202], xx[202];
inline bool EqualOfFloats(const double &a, const double &b)
{
return fabs(a-b) < eps;
}
int Find(const double x)
{
int left = 0, right = nx-1;
while (left != right)
{
int mid = (left+right)>>1;
if (xx[mid] == x)
return mid+1;
else if (xx[mid] < x)
left = mid+1;
else
right = mid-1;
}
return left+1;
}
void Modify(const int p, const int left, const int right)
{
if (st <= left && right <= ed)
{
if (s[p].count+x == 0)
s[p].length = s[2*p].length+s[2*p+1].length;
else if (s[p].count+x == 1)
s[p].length = xx[right-1]-xx[left-1];
s[p].count += x;
return;
}
if (right-left <= 1) return;
int mid = (left+right)>>1;
if (st <= mid) Modify(p*2, left, mid);
if (mid <= ed) Modify(p*2+1, mid, right);
if (!s[p].count) s[p].length = s[2*p].length+s[2*p+1].length;
}
int main()
{
ios::sync_with_stdio(false);
while (cin >> n, n)
{
ny = nl = nx = 0;
for (int i = 0; i < n; ++i)
{
double x1, x2, y1, y2;
cin>> x1 >> y1 >> x2 >> y2;
xx[nx++] = x1, xx[nx++] = x2;
yy[ny++] = y1, yy[ny++] = y2;
line[nl++] = Line(x1, x2, y1, false);
line[nl++] = Line(x1, x2, y2, true);
}
sort(line, line+nl);
sort(yy, yy+ny);
ny = unique(yy, yy+ny, EqualOfFloats)-yy;
sort(xx, xx+nx);
nx = unique(xx, xx+nx, EqualOfFloats)-xx;
memset(s, 0, sizeof(s[0])*8*nx);
double S = .0;
int NextLine = 0;
for (int i = 0; i < ny-1; ++i)
{
while (NextLine < nl && line[NextLine].y == yy[i])
{
st = Find(line[NextLine].left), ed = Find(line[NextLine].right);
x = line[NextLine++].ToDelete ? -1 : 1;
Modify(1, 1, nx);
}
S += (yy[i+1]-yy[i])*s[1].length;
}
cout << "Test case #" << ++T << endl;
cout << "Total explored area: " << fixed << setprecision(2) << S << endl << endl;
}
}
|