| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
1A留念,贴个垃圾深搜代码#include <iostream>
#include <memory.h>
using namespace std;
int w,h;
int map[22][22];
int ans;
int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
void dfs(int x,int y)
{
if(x<=h&&x>0&&y<=w&&y>0)
if(map[x][y]==0)
{
map[x][y] = 1;
ans++;
for(int i=0;i<4;i++)
dfs(x+dir[i][0],y+dir[i][1]);
}
return ;
}
int main()
{
while(cin>>w>>h)
{
if(w==0&&h==0)
break;
int x,y;
char temp;
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++)
{
cin>>temp;
if(temp=='.')
map[i][j] = 0;
else if(temp=='#')
map[i][j] = 1;
else if(temp=='@')
{
map[i][j] = 0;
x = i;
y = j;
}
}
ans = 0;
dfs(x,y);
cout<<ans<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator