-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2583bj.cpp
More file actions
82 lines (67 loc) · 1.57 KB
/
2583bj.cpp
File metadata and controls
82 lines (67 loc) · 1.57 KB
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
#include <iostream>
#include <utility>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
int m, n, k;
int board[105][105]; //격자의 경우는 x,y축 기존 개념대로
int vis[105][105];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int cnt = 0;
cin >> m >> n >> k;
while (k--) { //뒤집은 모습(x,y바꾼) 직사각형 색칠 작업
int x, y;
cin >> x >> y;
//board[y][x] = 1; //색칠
int xx, yy;
cin >> xx >> yy;
//board[yy][xx] = 1;
for (int i = y; i <= yy-1; i++) {
for (int j = x; j <= xx-1; j++) {
board[i][j] = 1;//직사각형 색칠
}
}
}
/*
for (int i = 0; i < m;i++) {
for (int j = 0; j < n; j++) {
cout << board[i][j]<<' ';
}
cout << '\n';
}*/
queue<pair<int, int> > q;
vector<int> area;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (vis[i][j] || board[i][j] != 0) continue; //0인곳만 탐색
vis[i][j] = 1; // 시작점 방문 처리
q.push({ i,j });
cnt++;
int areacnt = 0;
while (!q.empty()) {
auto cur = q.front(); q.pop();
areacnt++;
for (int dir = 0; dir < 4; dir++) {
int nx = cur.first + dx[dir];
int ny = cur.second + dy[dir];
if (nx<0 || nx>=m || ny<0 || ny>=n) continue;
if (vis[nx][ny]||board[nx][ny]!=0) continue;
vis[nx][ny] = 1;
q.push({ nx,ny });
}
}
area.push_back(areacnt);
}
}
sort(area.begin(), area.end());
cout << cnt<<'\n';
for (auto a : area) {
cout << a<<' ';
}
return 0;
}