DFS (connected block) HDU 1241 oil deposits

Source: Internet
Author: User

Topic Portal

1 /*2 dfs: Oilfield problem, a classic DFS-seeking connectivity block. The original problem, but now it looks like this.3 */4 /************************************************5 Author:running_time6 Created time:2015-8-4 10:11:117 File Name:HDOJ_1241.cpp8 ************************************************/9 Ten#include <cstdio> One#include <algorithm> A#include <iostream> -#include <sstream> -#include <cstring> the#include <cmath> -#include <string> -#include <vector> -#include <queue> +#include <deque> -#include <stack> +#include <list> A#include <map> at#include <Set> -#include <bitset> -#include <cstdlib> -#include <ctime> - using namespacestd; -  in #defineLson L, Mid, RT << 1 - #defineRson mid + 1, R, RT << 1 | 1 totypedefLong Longll; + Const intMAXN = 1e2 +Ten; - Const intINF =0x3f3f3f3f; the Const intMOD = 1e9 +7; * CharMAZE[MAXN][MAXN]; $ BOOLVIS[MAXN][MAXN];Panax Notoginseng intdx[8] = {-1,1,0,0, -1, -1,1,1}; - intdy[8] = {0,0, -1,1, -1,1, -1,1}; the intN, M; +  A BOOLJudgeintXinty) { the     if(X <1|| X > N | | Y <1|| Y > M | | Vis[x][y] | | Maze[x][y]! ='@')return false; +     return true; - } $  $ voidDFS (intXinty) { -      for(intI=0; i<8; ++i) { -         inttx = x + dx[i], Ty = y +Dy[i]; the         if(!judge (TX, Ty))Continue; -Vis[tx][ty] =true; DFS (TX, ty);Wuyi     } the } -  Wu intMainvoid)    {//HDU 1241 Oil Deposits -      while(SCANF ("%d%d", &n, &m) = =2) { About         if(M = =0) Break; $          for(intI=1; i<=n; ++i) { -scanf ("%s", Maze[i] +1); -         } -memset (Vis,false,sizeof(Vis)); A         intAns =0; +          for(intI=1; i<=n; ++i) { the              for(intj=1; j<=m; ++j) { -                 if(Maze[i][j] = ='@'&&!Vis[i][j]) { $ans++; VIS[I][J] =true; DFS (i, j); the                 } the             } the         } theprintf ("%d\n", ans); -     } in  the     return 0; the}

DFS (connected block) HDU 1241 oil deposits

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.