-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Counting_Rooms.cpp
More file actions
48 lines (45 loc) · 881 Bytes
/
A_Counting_Rooms.cpp
File metadata and controls
48 lines (45 loc) · 881 Bytes
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 1000
char adjList[1000][1000];
bool vis[1000][1000];
ll n, m;
bool check(ll i, ll j)
{
if (i >= 0 && j >= 0 && i < n && j < m && !vis[i][j] && adjList[i][j] == '.')
return 1;
else
return 0;
}
void recursion(ll i, ll j)
{
if (check(i, j) == 0)
return;
vis[i][j] = 1;
recursion(i + 1, j);
recursion(i, j + 1);
recursion(i - 1, j);
recursion(i, j - 1);
}
int main()
{
cin >> n >> m;
for (ll i = 0; i < n; i++)
{
for (ll j = 0; j < m; j++)
cin >> adjList[i][j];
}
memset(vis, 0, sizeof vis);
ll ans = 0;
for (ll i = 0; i < n; i++)
{
for (ll j = 0; j < m; j++)
{
if (check(i, j))
ans++;
recursion(i, j);
}
}
cout << ans;
}