###### 初学DFS:HDU1241 Oil deposits

#include <iostream>
#include <cstdio>
#include <cstring>
//#define test
using namespace std;
char vis[105][105];
int cnt;
int M,N;
int dir[8][2] = {{0,1},{1,0},{-1,0},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
void dfs(int x,int y)
{
vis[x][y]='*';
//printf("%d %d\n",x,y);
int xx,yy;
for(int i=0; i<8; i++)
{
xx=x+dir[i][0];
yy=y+dir[i][1];
if(xx>M||yy>N||xx<1||yy<1||vis[xx][yy]=='*')
continue;
if(vis[xx][yy]=='@')
dfs(xx,yy);
}
return;
}
int main()
{
//fp=fopen("out.txt","w");
while(scanf("%d %d",&M,&N)!=EOF)
{
getchar();
if(M==0||N==0)
break;
for(int i=1; i<=M; i++)
{
for(int j=1; j<=N; j++)
scanf("%c",&vis[i][j]);
getchar();//get the char '\n'
}
#ifdef test
for(int i=1; i<=M; i++)
{
for(int j=1; j<=N; j++)
printf("%c",vis[i][j]);
printf("\n");
}
#endif
cnt=0;
for(int i=1; i<=M; i++)
for(int j=1; j<=N; j++)
if(vis[i][j]=='@')
{
cnt++;
dfs(i,j);
}
printf("%d\n",cnt);
//memset(vis,0,sizeof(vis));
}
return 0;
}



#### ACM-DFS之Oil Deposits——hdu1241

2014-02-25 12:47:46

#### hdu1241（Oil Deposits）

2015-08-02 21:01:50

#### hdu1241 Oil Deposits (bfs水题)

2017-05-27 20:17:12

#### hdu1241 Oil Deposits（dfs&&bfs）

2016-09-23 10:12:50

#### Oil Deposits(基础dfs)

2016-02-28 09:46:59

#### 杭电1241 HDU acm --Oil Deposits---DFS深度优先算法实现详解

2013-05-27 14:15:33

#### DFS入门精讲：油田（Oil Deposits UVA572）

2017-05-23 20:02:09

#### ZOJ1709/POJ1562 油田问题/搜索/DFS

2015-07-25 10:46:23

#### Oil Deposits(dfs深搜)

2015-08-13 02:25:42

#### [ACM - 深度优先搜索]Oil Deposits

2013-11-27 09:22:55