也是连通块的面积问题(flood fill)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
#define x first
#define y second
typedef pair<int,int> pii;
const int N = 200;
char g[N][N];
pii q[N*N];
int sx, sy;
bool st[N][N];
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int n,m;
int bfs(int sx, int sy){
int hh = 0, tt = 0;
q[0] = {sx,sy};
st[sx][sy] = true;
int ans = 0;
while(hh <= tt){
ans++;
pii t = q[hh++];
for(int i = 0; i < 4; i++){
int a = t.x + dx[i], b = t.y + dy[i];
if(a >= 1 && a <= n && b >= 1 && b <= m && !st[a][b] && g[a][b] == '.'){
st[a][b] = true;
q[++tt] = {a,b};
}
}
}
return ans;
}
int main(){
cin >> m >> n;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> g[i][j];
if(g[i][j] == '@'){
sx = i;
sy = j;
}
}
}
cout << bfs(sx,sy);
return 0;
}