Personally I feel this question is very simple, that is a completely machined block to find the number of China Unicom
Individual problem-solving ideas is to read, then loop again, getting to the water to dfs, China Unicom and the block "delete" where the w, and adding one to answer
Last answer output
Specific comments see program :::
. 1 #include <the cmath> 2 #include <cstdio> . 3 #include <the iostream> . 4 #include <CString> . 5 #include <algorithm> . 6 the using namespace STD; . 7 int n-, m, ANS; . 8 BOOL A [ 105 ] [ 105 ]; // I Boolean array, in both cases anyway . 9 void DFS ( int X, int Y) { // DFS 10 A [X] [Y] = to false ; // delete the communication block . 11 IF (X + . 1 <= n && a [x +. 1 ] [Y]) DFS (X + . 1 , Y); // if the following water (...), down search 12 is IF (Y + . 1 <= m && A [X] [Y + . 1 ]) DFS (X, Y + 1 ); // if water is left, left search, y is compared with the note m, do not put m, n confuse 13 is IF (X- 1 > = 1 && A [X- 1 ] [y]) DFS (X- . 1 , Y); // up search 14 IF (Y- . 1 > = . 1 && A [X] [Y- . 1 ]) DFS (X, Y- . 1 ); // right search 15 IF (X + . 1 <= Y + n-&& . 1 <&& A m = [X +. 1 ] [Y + . 1 ]) DFS (X + . 1 , Y + . 1 ); // left on the search 16 IF (X + . 1 <= n-&& Y- . 1 > = . 1 && A [X + . 1 ] [Y- . 1 ]) DFS (X + . 1 , Y- . 1 ); // the right search . 17 IF (X- . 1 > = . 1 && Y + . 1 <= m && A [X- . 1 ] [Y + . 1 ]) DFS (X- . 1 , Y + . 1 ); // left search under 18 IF (X- . 1 > = . 1Y- && . 1 > = . 1 && A [X- . 1 ] [Y- . 1 ]) DFS (X- . 1 , Y- . 1 ); // right next search . 19 } 20 is void SC () { // This is my personal debugging when using the program, the communication block is deleted see which one, students may be interested to see ~~~ 21 is for ( int I = . 1 ; I <= n-; I ++ ) { 22 is for ( int J = . 1 ; J <= m; J ++ ) { 23 is IF (A [I] [J]) << COUT " W " ; 24 the else COUT << " . "; 25 } 26 is COUT << endl; 27 } 28 } 29 int main () { // main function 30 CIN >> >> n-m; // read 31 is for ( int I = . 1 ; I <= n-; I ++ ) { 32 string X; // definition of string, although separate a string variable, but can be accessed directly by a suffix 33 is CIN >> X; // read-type continuous period char string, more convenient 34 is for ( int J = . 1 ; J <= m; J ++ ) { 35 IF (X [J- . 1] == ' . ' ) A [I] [J] = to false ; // note that, x is from 0 for the location of the start of reading, if the block is not the water, whether to assign 36 the else A [I] [J ] = to true ; // otherwise is 37 [ } 38 is } 39 for ( int I = . 1 ; I <= n-; I ++) { // analog 40 for ( int J = . 1 ; J <= m; J ++ ) { 41 is IF (A [I] [J]) { // if the water 42 is // COUT << << I '' J << << endl; debugging with individual 43 is DFS (I, J); //Remove the communication block 44 is // SC (); debugging individual with 45 ANS ++; // number plus an answer 46 is } 47 } 48 } 49 COUT ANS << << endl; // output answer 50 return 0 ; 51 is } // perfect end Finally, I wish you happy every day, the program successfully (...)
Newcomers are encouraged to open Bo about it ~ ~ ~