-
Notifications
You must be signed in to change notification settings - Fork 2
/
10703.cpp
57 lines (52 loc) · 1.16 KB
/
10703.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
/*
Solution to 10703
*/
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
long long w,h,n;
long long x1,y1,x2,y2;
bool empty[500][500];
cout << endl;
while(1)
{
cin >> w >> h >> n;
if( w == 0 && h == 0 && n == 0)
break;
//Initialize all spots to empty
for(int i = 0; i < 500; i++)
for(int j = 0; j < 500; j++)
empty[i][j] = true;
for(int i = 0; i < n; i++)
{
//Get input and find the bottom left and top right corner
cin >> x1 >> y1 >> x2 >> y2;
x1--; y1--; x2--; y2--;
if(x1 > x2)
swap(x1,x2);
if(y1 > y2)
swap(y1, y2);
//All spots in rectangle formed by those two points as not empty
for(int i = y1; i <= y2; i++)
for(int j = x1; j <= x2; j++)
if(empty[i][j])
empty[i][j] = false;
}
//Count the number of empty spots
unsigned long long count = 0;
for(int i = 0; i < h; i++)
for(int j = 0; j < w; j++)
if(empty[i][j])
count++;
if(count == 0)
cout << "There is no empty spots.";
else if(count == 1)
cout << "There is one empty spot.";
else
cout << "There are " << count << " empty spots.";
cout << endl;
}
return 0;
}