逸尘 • 1年前
using namespace std; int w, h, ans, x, y; bool bj[55][55];
void dfs(int x, int y) {
ans++;
bj[x][y] = 0;
if (bj[x - 1][y] == 1) {
dfs(x - 1, y);
}
if (bj[x + 1][y] == 1) {
dfs(x + 1, y);
}
if (bj[x][y - 1] == 1) {
dfs(x, y - 1);
}
if (bj[x][y + 1] == 1) {
dfs(x, y + 1);
}
return;
}
int main() {
cin >> h >> w;
char s;
for (int i = 1; i <= w; i++) {
for (int j = 1; j <= h; j++) {
cin >> s;
if (s == '@') {
x = i;
y = j;
bj[i][j] = 1;
} else if (s == '.') {
bj[i][j] = 1;
}
}
}
dfs(x, y);
cout << ans;
return 0;
}
评论:
请先登录,才能进行评论