#include
#include
#include
#include
using namespace std;
int m,n;
char map[105][105];
void dfs(int x,int y)
{//现在的位置是(x,y)
map[x][y]='*';//将现在的位置替换为.
//循环遍历移动8个方向
for(int dx=-1;dx<=1;dx++)
{//向x方向移动x,向y方向移动y,移动结果是(nx,ny)
for(int dy=-1;dy<=1;dy++)
{
int nx=x+dx;
int ny=dy+y;
//判断(nx,ny)是否在院子里,以及是否有积水
if(nx>=0&&nx=0&&ny<m&&map[nx][ny]=='@')
dfs(nx,ny);
}
}
}
void solve()
{
int i,j;
int ans=0;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(map[i][j]=='@')
{//从有水的地方开始dfs
dfs(i,j);
ans++;
}
}
}
printf("%d\n",ans);
}
int main()
{
int i,j;
while(scanf("%d%d",&n,&m)!=EOF&&n&&m)
{
getchar();//在这多加了一个getchar(),让我WA了一上午!!!
for(i=0;i<n;i++)
{
getchar();
for(j=0;j<m;j++)
{
scanf("%c",&map[i][j]);
}
}
solve();
}
return 0;
}
poj1064那道题,我的代码怎么老是不通过?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
0条回答 默认 最新
悬赏问题
- ¥50 树莓派安卓APK系统签名
- ¥15 maple软件,用solve求反函数出现rootof,怎么办?
- ¥65 汇编语言除法溢出问题
- ¥15 Visual Studio问题
- ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
- ¥20 求一个html代码,有偿
- ¥100 关于使用MATLAB中copularnd函数的问题
- ¥20 在虚拟机的pycharm上
- ¥15 jupyterthemes 设置完毕后没有效果
- ¥15 matlab图像高斯低通滤波