From 4fbd999f3ae0bc7fa4470cd14d0c81ec51ba5f7d Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Thu, 1 Jul 2021 07:46:21 +0800 Subject: [PATCH] P1596 [USACO10OCT]Lake Counting S R52232058 --- Luogu/problem/P1596/P1596.cpp | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Luogu/problem/P1596/P1596.cpp diff --git a/Luogu/problem/P1596/P1596.cpp b/Luogu/problem/P1596/P1596.cpp new file mode 100644 index 00000000..0579ec30 --- /dev/null +++ b/Luogu/problem/P1596/P1596.cpp @@ -0,0 +1,42 @@ +#include + +using namespace std; + +int n, m, ans; +char c; +bool w[105][105]; + +void dfs(int x, int y) { + if (x < 0 || x >= n || y < 0 || y >= m || !w[x][y]) { + return; + } + w[x][y] = false; + dfs(x - 1, y - 1); + dfs(x - 1, y); + dfs(x - 1, y + 1); + dfs(x, y - 1); + dfs(x, y + 1); + dfs(x + 1, y - 1); + dfs(x + 1, y); + dfs(x + 1, y + 1); +} + +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> c; + w[i][j] = c == 'W' ? true : false; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (w[i][j]) { + dfs(i, j); + ans++; + } + } + } + cout << ans << endl; + return 0; +}