Find out how many "puddles" (W's unicom blocks)
Sample Input
10 12
W........ Ww.
. Www..... Www
..... WW ... Ww.
......... Ww.
......... W..
.. W...... W..
. W.w ..... Ww.
W.w.w ..... W.
. W.W ... W.
.. W.......W.
Sample Output
3
Thinking of solving problems
Dfs
Code
#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;Const intMAXN = the;CharPIC[MAXN][MAXN];intVIS[MAXN][MAXN];intHigh,width;intCNT =0;voidDfsintXintY) {//Line x, column y if(Pic[x][y] = ='. '|| Vis[x][y])return;if(x<0|| y<0|| X>=high | | Y>=width)return; Vis[x][y] =1; DFS (X-1, y);d FS (x+1, y);d FS (x,y+1);d FS (x,y-1); DFS (X-1, Y1);d FS (X-1, y+1);d FS (x+1, Y1);d FS (x+1, y+1);}intMain () {scanf("%d%d", &high,&width); for(inti =0; I < high; i + +)scanf('%s ', Pic[i]); for(inti =0; I < high; i + +) { for(intj =0; J < width; J + +) {if(Pic[i][j] = ='. ')Continue;if(Vis[i][j] = =0) {DFS (I,J); CNT + +; } } }printf("%d\n", CNT);return 0;}
POJ2386 Lake Counting Map Dfs