图的深搜。
#include <cstdio>
#include <cstring>
const int MAXN = 20;
char map[MAXN+2][MAXN+2];
int cnt = 0;
int w, h;
void Dfs(int x, int y)
{
cnt++;
map[x][y] = '#';
if (x - 1 >= 0 && map[x-1][y] == '.') {
Dfs(x-1, y);
}
if (x + 1 < h && map[x+1][y] == '.') {
Dfs(x+1, y);
}
if (y - 1 >= 0 && map[x][y-1] == '.') {
Dfs(x, y-1);
}
if (y + 1 < w && map[x][y+1] == '.') {
Dfs(x, y+1);
}
}
int main()
{
while (scanf("%d%d", &w, &h) == 2 && w && h) {
int i;
for (i = 0; i < h; i++) {
scanf("%s", map[i]);
}
int j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
if (map[i][j] == '@') {
Dfs(i, j);
break;
}
}
}
printf("%d\n", cnt);
cnt = 0;
for (i = 0; i < h; i++) {
memset(map, 0, sizeof(int) * w);
}
}
return 0;
}