-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-25.cpp
More file actions
95 lines (73 loc) · 1.76 KB
/
3-25.cpp
File metadata and controls
95 lines (73 loc) · 1.76 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
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <cstring>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int arr[101][101] = {0,};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
struct pos{
int x;
int y;
};
int bfs(int i , int j, int mexx , int mexy)
{
queue <pos> que;
int cnt = 1;
pos nowidx = {i,j};
pos searchidx;
que.push(nowidx);
arr[nowidx.x][nowidx.y] = 1;
while(!que.empty())
{
nowidx = que.front();
que.pop();
for(int i = 0 ; i < 4 ;i++)
{
searchidx.x = nowidx.x + dx[i];
searchidx.y = nowidx.y + dy[i];
if(searchidx.x >= 0 && searchidx.x <= mexx && searchidx.y >= 0 && searchidx.y <= mexy)
{
if(arr[searchidx.x][searchidx.y] == 0)
{
que.push(searchidx);
cnt++;
arr[searchidx.x][searchidx.y] = 1;
}
}
}
}
return cnt;
}
int main(void)
{
int n,m,k;
cin>>n>>m>>k;
pos pos1,pos2;
int result_arr[10000];
int cnt = 0;
for(int i = 0 ; i < k ;i++)
{
cin>>pos1.y>>pos1.x>>pos2.y>>pos2.x;
pos2.x--;
pos2.y--;
for(int a = pos1.x ; a <= pos2.x ; a++)
for(int b = pos1.y ; b <= pos2.y ; b++)
arr[a][b] = 1;
}
for(int i = 0 ; i < n ;i++)
{
for(int j = 0 ; j < m ;j++)
if(arr[i][j] == 0)
{
result_arr[cnt++] = bfs(i,j,n-1,m-1);
}
}
sort(result_arr,result_arr+cnt);
cout<<cnt<<"\n";
for(int i = 0 ; i < cnt ; i++)
cout<<result_arr[i]<<" ";
cout<<"\n";
return 0;
}