提交时间:2023-10-31 21:22:26
运行 ID: 29618
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt = 0; cin >> n; char a[n + 1][n + 1]; 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[i][j] == '@') { 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 i = 1; i <= n; ++ i) { for (int j = 1; j <= n; ++ j) { if (a[i][j] == '@') cnt ++; } } cout << cnt; return 0; }