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;
}
相关文章推荐
- HDU--1312 -- Red and Black [简单DFS]
- HDU 1312 Red and Black (dfs基础题)
- hdu 1312 Red and Black(深搜)
- hdu 1312
- HDU 1312(BFS)
- HDU 1312 Numerically Speaking
- hdu 1312
- HDU 1312 Red and Black DFS(深度优先搜索) 和 BFS(广度优先搜索)
- Hdu 1312 Red and Black
- HDU 1312:Red and Black
- 文章标题 HDU 1312 : Numerically Speaking (BFS)
- HDU 1312 Red and Black 【DPS】
- 【HDU 1312 Red and Black】+ DFS + BFS
- hdu 1312 Red and Black (简单dfs)
- HDU 1312 Red and Black DFS深搜
- hdu 1312 Red and Black
- HDU 1312 BFS
- HDU - 1312 : Red and Black(dfs、bfs)
- hdu 1312 Red and Black
- hdu-1312