# Include <iostream> # include <stdio. h> // # define dbgusing namespace STD; const int maxsize = 10000; char map [maxsize] [maxsize]; int n, m; unsigned long lakecounts; bool ifirstlake = true; bool icounted = true; void DFS (int x, int y) {int M, N; n = x; M = y; // border condition, if (M> = M | M <0) return; If (n> = n | n <0) return; if (Map [N] [m] = 'W') {// If (! Ifirstlake) // {If (! Icounted) {lakecounts ++; # ifdef dbg cout <"Lake counts add! "; Cout <Endl; cout <" at line: "<n; cout <" column: "<m <Endl; # endif icounted = true ;} ///}/* If (ifirstlake) {ifirstlake = false; icounted = false ;} */# ifdef dbg cout <"this is line" <n <"column" <m; cout <"and this is" <map [N] [m] <Endl; # endif map [N] [m] = '. '; DFS (x + 1, Y); DFS (x-1, Y); // <-> DFS (X, Y + 1); DFS (x, Y-1 ); // parse DFS (x + 1, Y + 1); DFS (x-1, Y-1); // DFS (x + 1, y- 1); DFS (x-1, Y + 1); //} int main () {char Buf; freopen ("B: \ ACM \ poj2386 \ input.txt "," r ", stdin); CIN> N> m; For (INT I = 0; I <N; I ++) for (Int J = 0; j <m; j ++) {CIN> Buf; If (BUF! = '\ 0') map [I] [J] = Buf;} // it seems that the search from 0 does not work # ifdef dbg for (INT I = 0; I <n; I ++) {for (Int J = 0; j <m; j ++) {cout <map [I] [J];} cout <Endl ;}# endif for (INT I = 0; I <n; I ++) {for (Int J = 0; j <m ;) {If (Map [I] [J]! = 'W') {J ++; continue;} // map [I] [J] = 'W'/* icounted = true; ifirstlake = true; */icounted = false; DFS (I, j); j ++ ;}}cout <lakecounts <Endl; // fclose (stdin ); // cout <"Hello world! "<Endl; return 0 ;}