点击打开链接
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=100+5;
int m,n;
char maze[maxn][maxn];
void dfs(int x,int y)
{
maze[x][y]='.';
for(int dx=-1;dx<=1;dx++)
for(int dy=-1;dy<=1;dy++)
{
int nx=x+dx,ny=y+dy;
if(nx>=0&&nx<m&&ny>=0&&ny<n&&maze[nx][ny]=='@') dfs(nx,ny);
}
}
int main()
{
while(scanf("%d%d",&m,&n)==2&&m)
{
for(int i=0;i<m;i++)
scanf("%s",maze[i]);
int res=0;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
if(maze[i][j]=='@') {
res++;
dfs(i,j);
}
cout<<res<<endl;
}
return 0;
}
hdu 1241
最新推荐文章于 2024-10-10 22:59:02 发布