-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCounting Rooms
More file actions
51 lines (45 loc) · 1.04 KB
/
Counting Rooms
File metadata and controls
51 lines (45 loc) · 1.04 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
//g++ 5.4.0
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
const int nax = 1e3+10;
bool vis[nax][nax];
int n , m;
bool check(int x, int y )
{
if( x >=0 && x<n && y>=0 && y<m ) return 1;
return 0;
}
void dfs(int x,int y)
{
vis[x][y] = 1;
if( check(x-1,y) && !vis[x-1][y] ) dfs( x-1,y) ;
if( check(x+1,y) && !vis[x+1][y] ) dfs( x+1,y) ;
if( check(x,y-1) && !vis[x][y-1] ) dfs( x,y-1) ;
if( check(x,y+1) && !vis[x][y+1] ) dfs( x,y+1) ;
return ;
}
signed main()
{
fast;
cin >> n >> m;
for(int i = 0 ; i < n ; i ++ )
{
string s;
cin >> s;
for(int j=0 ; j < m ; j++ )
{
if( s[j] == '.' ) vis[i][j] = 0;
else vis[i][j] = 1;
}
}
int ans= 0 ;
for(int i = 0 ; i < n ; i ++ )
for(int j=0 ; j < m ; j++ )
if( !vis[i][j] ) dfs(i,j) , ans++;
cout << ans;
}