-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaekJoon2583.cpp
72 lines (65 loc) · 1.36 KB
/
BaekJoon2583.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
//BaekJoon 2583 영역 구하기
#include <iostream>
#include <string>
#include <queue>
#include <list>
#include <utility>
using namespace std;
int m, n, k;
int arr[100][100];
bool visited[100][100] = { false, };
list <int> li;
queue<pair<int, int>> qu;
int cnt = 0;
int isNear(int a, int b) {
if (a < 0 || b < 0 || a >= m || b >= n) return 0;
if (arr[a][b] == 0 && visited[a][b] == false) {
qu.push(make_pair(a, b));
visited[a][b] = true;
return 1;
}
return 0;
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> m >> n >> k;
for (int i = 0; i < k; i++) {
int a, b, c, d;
cin >> b >> a >> d >> c;
c--; d--;
for (int j = a; j <= c; j++) {
for (int t = b; t <= d; t++) {
arr[j][t] = 1;
}
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (arr[i][j] == 1 || visited[i][j] == true) continue;
qu.push(make_pair(i, j));
visited[i][j] = true;
int numArr = 1;
cnt++;
while (!qu.empty()) {
pair<int, int> cur = qu.front();
qu.pop();
int a = cur.first;
int b = cur.second;
numArr += isNear(a - 1, b);
numArr += isNear(a, b + 1);
numArr += isNear(a + 1, b);
numArr += isNear(a, b - 1);
}
li.push_back(numArr);
}
}
li.sort();
cout << cnt << "\n";
list<int>::iterator iter;
for (iter = li.begin(); iter != li.end(); ++iter) {
cout << *iter << " ";
}
return 0;
}