-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDien_tich.cpp
More file actions
50 lines (50 loc) · 1.3 KB
/
Dien_tich.cpp
File metadata and controls
50 lines (50 loc) · 1.3 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
#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[1005][1005];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool used[1005][1005];
int dp[1005][1005];
int main()
{
cin >> n >> m;
memset(used, false, sizeof(used));
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
cin >> a[i][j];
}
}
queue<pair<int, int>> q;
for(int i = 1; i <= n; i++)
{
int dem;
for(int j = 1; j <= m; j++)
{
dem = 0;
if(a[i][j] == '.' && !used[i][j])
{
dem++;
q.push({i, j});
used[i][j] = true;
while (!q.empty())
{
pair<int, int> x = q.front(); q.pop();
for(int k = 0; k < 4; k++)
{
int ii = x.first + dx[k], jj = x.second + dy[k];
if(ii >= 1 && ii <= n && jj >= 1 && jj <= m && a[ii][jj] == '.' && !used[ii][jj])
{
dem++;
q.push({ii, jj});
used[ii][jj] = true;
}
}
}
cout << dem << " ";
}
}
}
}