您的位置:首页 > 其它

HDU 1312

2014-04-30 18:35 232 查看

#include<stdio.h>
#include<string.h>
char str[22][22];
int temp[22][22];
int cnt,h,w;
void dfs(int x,int y)
{
cnt ++;
temp[x][y] = 1;
if(!temp[x+1][y]&& x+1 < w)
dfs(x+1,y);
if(!temp[x-1][y] && x-1 > -1)
dfs(x-1,y);
if(!temp[x][y+1] && y+1 < h)
dfs(x,y+1);
if(!temp[x][y-1] && y-1 > -1)
dfs(x,y-1);
}

int main()
{
int i,j,a,b;
while(~scanf("%d%d",&h,&w)&&h+w)
{
cnt = 0;
for(i = 0;i < w;i ++)
{
scanf("%s",str[i]);
for(j = 0;j < h;j ++)
{
if(str[i][j] == '#')
temp[i][j] = 1;
if(str[i][j] == '.')
temp[i][j] = 0;
if(str[i][j] == '@')
{
a = i;
b = j;
}
}
}
dfs(a,b);
printf("%d\n",cnt);
}
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: