-
Notifications
You must be signed in to change notification settings - Fork 0
/
2583.cpp
66 lines (59 loc) · 1.33 KB
/
2583.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
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#define PAIR pair<int,int>
using namespace std;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int graph[100][100];
int visited[100][100];
queue<PAIR> q;
int M,N,K;
int bfs(int sx,int sy){
int cnt=1;
q.push(PAIR(sx,sy));
visited[sy][sx]=1;
while(!q.empty()){
int vx=q.front().first;
int vy=q.front().second;
q.pop();
for(int i=0; i<4;i++){
int xx = vx+dx[i];
int yy = vy+dy[i];
if(xx>=0&&yy>=0&&xx<N&&yy<M&&visited[yy][xx]==0&&graph[yy][xx]==0){
q.push(PAIR(xx,yy));
visited[yy][xx]=1;
cnt++;
}
}
}
return cnt;
}
int main(){
cin >> M>>N>>K;
int cnt=0;
vector<int> re;
for(int i =0; i<K; i++){
int lbx,lby,rtx,rty;
cin>>lbx>>lby>>rtx>>rty;
for(int i=lby;i<rty;i++){
for(int j=lbx;j<rtx;j++){
graph[i][j]=1;
}
}
}
for(int i=0;i<M;i++){
for(int j=0; j<N; j++){
if(graph[i][j]==0&&visited[i][j]==0){
re.push_back(bfs(j,i));
cnt++;
}
}
}
sort(re.begin(),re.end());
cout << cnt <<"\n";
for(int i=0; i<cnt;i++){
cout<<re[i]<< " ";
}
}