[ACM-POJ] poj2386, Lake counting

Source: Internet
Author: User
# 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 ;}

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.