HDU 1312
2014-04-30 18:35
190 查看
#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;
}
相关文章推荐
- 深度搜索DFS hdu-1312
- HDU 1312 BFS裸题
- HDU-1312-Red and Black(搜索)
- hdu 1312 Red and Black
- HDU1312 Red and Black
- hdu1312
- hdu 1312简单bfs
- Red and Black(HDU 1312)
- hdu 1312 Red and Black(dfs)
- 杭电(hdu)ACM 1312 Red and Black
- 图论 DFS HDU 1312
- HDU1312 Red and Black (DFS || BFS)
- HDU(1312)Red and Black(简单dfs)
- hdu 1312 bfs
- hdu1312 red and black 【递归】
- hdu 1312 Red and Black
- hdu 1312
- hdu-1312 Red and Black
- hdu 杭电 1312 Red and Black
- HDU 1312 Red and Black(dfs)