#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=100+10;
char g[maxn][maxn];
int d[maxn][maxn];
int m,n;
void dfs(int x,int y){
d[x][y]=1;
for(int i=-1;i<=1;i++)
for(int j=-1;j<=1;j++)
if(!(i==0&&j==0)){
if(x+i<0||x+i>=m||y+j<0||y+j>=n)continue;
else if(!d[x+i][y+j] && g[x+i][y+j]=='@')
dfs(x+i,y+j);
}
}
int main(){
while(scanf("%d%d",&m,&n)==2 && m){
for(int i=0;i<m;i++)scanf("%s",g[i]);
memset(d,0,sizeof(d));
int count=0;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
if(g[i][j]=='@' && !d[i][j]){
count++;
dfs(i,j);
}
printf("%d\n",count);
}
return 0;
}
HDU 1241 Oil Deposits油田问题(DFS)
最新推荐文章于 2020-07-28 17:25:32 发布