-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaps.cpp
139 lines (114 loc) · 3.07 KB
/
maps.cpp
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lineSweep.in");
ofstream fout("maps.out");
const int inf = INT_MAX / 2;
const int maxP = 400;
class rect
{
public:
double x1;
double y1;
double x2;
double y2;
};
class line
{
public:
int x;
int y1;
int y2;
bool operator<(const line & temp) const
{
return x < temp.x;
}
};
line _line(int x, int y1, int y2)
{
line temp{x, y1, y2}; return temp;
}
int main()
{
fout << fixed << setprecision(2);
int t = 0;
while (true)
{
int n = 0; fin >> n;
if (n == 0) break;
++t;
vector<rect> a_t(n);
set<double> _set;
for (int i = 0; i <= n - 1; ++i)
{
double t1, t2, t3, t4; fin >> t1 >> t2 >> t3 >> t4;
a_t[i].x1 = min(t1, t3);
a_t[i].y1 = min(t2, t4);
a_t[i].x2 = max(t1, t3);
a_t[i].y2 = max(t2, t4);
_set.insert(a_t[i].x1);
_set.insert(a_t[i].y1);
_set.insert(a_t[i].x2);
_set.insert(a_t[i].y2);
}
int _i = 0;
vector<double> itod;
map<double, int> dtoi;
for (auto it = _set.begin(); it != _set.end(); ++it)
{
double x = *it;
itod.push_back(x);
dtoi[x] = _i;
++_i;
}
vector<rect> a(n);
for (int i = 0; i <= n - 1; ++i)
{
a[i].x1 = dtoi[a_t[i].x1];
a[i].y1 = dtoi[a_t[i].y1];
a[i].x2 = dtoi[a_t[i].x2];
a[i].y2 = dtoi[a_t[i].y2];
}
vector<line> l;
for (int i = 0; i <= n - 1; ++i)
{
l.push_back(_line(a[i].x1, a[i].y1, a[i].y2));
l.push_back(_line(a[i].x2, a[i].y1, a[i].y2));
}
sort(l.begin(), l.end());
int sizeL = l.size();
vector<double> h(sizeL, 0.0);
for (int i = 0; i <= sizeL - 2; ++i)
{
int nowX = l[i].x, nextX = l[i + 1].x;
if (nowX == nextX) continue;
vector<int> thisH(maxP, 0);
for (int j = 0; j <= n - 1; ++j)
{
if (a[j].x1 <= nowX && nextX <= a[j].x2)
{
for (int y = a[j].y1; y <= a[j].y2 - 1; ++y)
{
thisH[y] = 1;
}
}
}
for (int y = 0; y <= maxP - 1; ++y)
{
if (thisH[y] == 1)
{
h[i] += (itod[y + 1] - itod[y]);
}
}
}
double ans = 0;
for (int i = 0; i <= sizeL - 2; ++i)
{
int nowX = l[i].x, nextX = l[i + 1].x;
ans += (h[i] * (itod[nextX] - itod[nowX]));
}
//ans = (int)(ans * 100.0 + 0.5) / 100.0;
fout << "Test case #" << t << '\n';
fout << "Total explored area: " << ans << "\n\n";
}
return 0;
}