-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP10703.cpp
55 lines (52 loc) · 1.17 KB
/
P10703.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
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> PP;
typedef vector<PP> Vector;
int main() {
int W, H, N, x1, y1, x2, y2;
Vector v[500];
while(true) {
cin >> W >> H >> N;
if(W+H+N == 0)
return 0;
for(int y = 0; y < H; ++y)
v[y].clear();
for(int i = 0; i < N; ++i) {
cin >> x1 >> y1 >> x2 >> y2;
--y1; --y2; --x1; --x2;
if(x1 > x2)
swap(x1,x2);
if(y1 > y2)
swap(y1,y2);
for(int y = y1; y <= y2; ++y)
v[y].push_back(PP(x1,x2));
}
int empty = 0;
for(int y = 0; y < H; ++y) {
sort(v[y].begin(), v[y].end());
int lastX = -1;
for(Vector::const_iterator it = v[y].begin(); it != v[y].end(); ++it) {
int left = it->first;
int right = it->second;
if(left <= lastX+1) {
if(lastX < right)
lastX = right;
}
else {
empty += left-lastX-1;
lastX = right;
}
}
empty += W-lastX-1;
}
if(empty == 0)
cout << "There is no empty spots." << endl;
else if(empty == 1)
cout << "There is one empty spot." << endl;
else
cout << "There are " << empty << " empty spots." << endl;
}
}