#include<cstdio>
#include<string>
int dir[4][2]={0,-1,-1,0,0,1,1,0};
int cnt;
char map[21][21];
int t[21][21];
int n,m;
void dfs(int x,int y)
{
if(t[x][y]==0)
{
cnt++;
t[x][y]=1;
}
int i;
for(i=0;i<4;i++)
{
int tx=x+dir[i][0];
int ty=y+dir[i][1];
if((!(tx<0||ty<0||tx>=n||ty>=m))
&&map[tx][ty]=='.')
{
map[tx][ty]='#';
dfs(tx,ty);
}
}
}
int main()
{
while(scanf("%d%d",&m,&n),(n||m))
{
int i,j;
int sx,sy;
for(i=0;i<n;i++)
{
getchar();
for(j=0;j<m;j++)
{
char c;
scanf("%c",&c);
if(c=='@')
{
sx=i;sy=j;
map[i][j]='.';
}
else map[i][j]=c;
}
}
memset(t,0,sizeof(t));
cnt=0;
dfs(sx,sy);
printf("%d\n",cnt);
}
return 0;
}
hdu1312 Red and Black
最新推荐文章于 2021-07-26 12:30:47 发布