提交时间:2023-10-31 22:06:37

运行 ID: 29660

#include <bits/stdc++.h> using namespace std; int main() { int n, cnt = 0; cin >> n; char a[n + 1][n + 1]; for (int i = 1; i <= n; ++ i){ for (int j = 1; j <= n; ++ j){ cin >> a[i][j]; } } int d; cin >> d; for (int i = 1; i <= d - 1; ++ i){ for (int j = 1; j <= n; ++ j){ for (int k = 1; k <= n; ++ k){ if (a[j][k] == '@'){ if (a[j - 1][k] == '.') a[j - 1][k] = '!'; if (a[j + 1][k] == '.') a[j + 1][k] = '!'; if (a[j][k - 1] == '.') a[j][k - 1] = '!'; if (a[j][k + 1] == '.') a[j][k + 1] = '!'; } } } for (int j = 1; j <= n; ++ j){ for (int k = 1; k <= n; ++ k){ if (a[j][k] == '!'){ a[j][k] = '@'; } } } } for (int i = 1; i <= n; ++ i){ for (int j = 1; j <= n; ++ j){ if (a[i][j] == '@') cnt ++; } } cout << cnt; return 0; }