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