Poj Lake counting 2386

Source: Internet
Author: User

The basic DFS question, read the Challenge Program Design book to have a preliminary understanding of this algorithm, through constant search for continuous changes, find the connected block, compile error was reported twice when the poj was submitted. The first time the compiler was not modified, it may be the reason why the question was not done for a long time. Then, it is necessary to add a loop when deciding whether to input it, as a result, while has one more bracket, and I didn't find this bug in codeblocks. Forget it. I 'd better practice ACM.

# Include <iostream>
# Include <cstdio>
Using namespace STD;
Const int max_n = 101, max_m = 101;
Int n, m;
Char field [max_n] [max_m];
Void DFS (int x, int y ){
Field [x] [Y] = '.';
For (INT xn =-1; XN <= 1; XN ++ ){
For (int yn =-1; YN <= 1; YN ++ ){
Int xx = xn + X;
Int YY = YN + Y;
If (0 <= XX & XX <= N & 0 <= YY & YY <= M & field [XX] [YY] = 'W ')
DFS (XX, YY );
}
}
}
Void solve (){
Int res = 0;
For (INT I = 0; I <n; I ++ ){
For (Int J = 0; j <m; j ++ ){
If (field [I] [J] = 'W '){
DFS (I, j );
Res ++;
}
}


}
Printf ("% d \ n", Res );
}
Int main (){
Cin> N> m;
// Char field [max_n] [max_n + 1];
For (INT I = 0; I <n; I ++ ){
For (Int J = 0; j <m; j ++ ){
Cin> Field [I] [J];
}
}
Solve ();

Return 0;
}

Poj Lake counting 2386

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.