-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-1-2.cpp
52 lines (46 loc) · 781 Bytes
/
2-1-2.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
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100;
const int MAXM = 100;
int N, M, m[MAXN][MAXM];
bool dfs(int i, int j) {
if (i < 0 || i >= N || j < 0 || j >= M || m[i][j] != 1) return false;
m[i][j] = 2;
for (int k = 0; k < 9; k++) {
int dx = k%3 - 1, dy = k/3 - 1;
dfs(i+dx, j+dy);
}
return true;
}
int main() {
string S;
cin >> N >> M;
for (int i = 0; i < N; i++) {
cin >> S;
for (int j = 0; j < M; j++) {
m[i][j] = (S[j] == '.') ? 0 : 1;
}
}
int cnt = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (dfs(i, j)) cnt++;
}
}
cout << cnt << endl;
return 0;
}
/*
10 12
W........WW.
.WWW.....WWW
....WW...WW.
.........WW.
.........W..
..W......W..
.W.W.....WW.
W.W.W.....W.
.W.W......W.
..W.......W.
=>3
*/