/* 1y 不錯的,昨天聽鐘超分析了dfs bdf 感覺好像有點懂起來了
這個題目的意思很簡單,一開始我想深搜的時候怕逾時,但是還是覺得可以,就敲代碼了,
可是遇到問題了,這個題目的行列輸入跟平時的不一樣,在這裡的就用了,傳統的習慣,糾結ing
跟糾結的@的地方用了map[si][sj] = false 結果答案少了1,後來進行調試,也是鐘超哪裡學來的
於是馬上發現錯誤了
*/
#include<iostream>//2374171 2010-04-23 12:59:21 Accepted 1312 15MS 300K 1053 B C++ 悔惜晟
#include<cstring>
using namespace std;
char map[22][22];
bool hash[22][22];
int w, h;
int count;
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
void dfs(int x, int y)
{
int i;
if(x < 0 || x >= h || y < 0 || y >= w)
return ;
for(i = 0; i < 4; i++)
{
int tx = x + dir[i][0];
int ty = y + dir[i][1];
//if(map[tx][ty] == '#' || map[tx][ty] )
//continue;
if(map[tx][ty] == '.' && !hash[tx][ty])
{
hash[tx][ty] = true;
dfs(tx, ty);
//hash[tx][ty] = false;
}
}
}
int main()
{
int i, j;
int si, sj;
while(cin>>w>>h)
{
if(w + h == 0)
continue;
for(i = 0; i < h; i++)
for(j = 0; j < w; j++)//列
{
cin>>map[i][j];
if(map[i][j] == '@')
{
si = i;
sj = j;
}
}
memset(hash, false , sizeof(hash));
hash[si][sj] = true; //@
count= 0;
dfs(si, sj);
int count = 0;
for(i = 0; i < h; i++)
for(j = 0; j < w; j++)//列
{
if(hash[i][j])
count++;
}
cout<<count<<endl;
}
}