提交时间:2024-01-21 14:02:30
运行 ID: 120940
# include <iostream> # include <memory.h> using namespace std; int main(){ int n,m; cin >> n; char computer[n+1][n+1]; bool memory[n+1][n+1]; for (int i = 0;i < n;i++){ for (int j = 0;j < n;j++){ cin >> computer[i][j]; } }cin >> m; for (int hour = 1;hour < m;hour++){ memset(memory,true,sizeof(memory)); for (int i = 0;i < n;i++){ for (int j = 0;j < n;j++){ if (computer[i][j] == '@' && memory[i][j]){ /* c[i-1][ j ] c[ i ][j-1] c[ i ][ j ] c[ i ][j+1] c[i+1][ j ] */ if (i - 1 >= 0){ if (computer[i-1][j] != '#'){ computer[i-1][j] = '@'; memory[i-1][j] = !memory[i-1][j]; } }if (i + 1 < n){ if (computer[i+1][j] != '#'){ computer[i+1][j] = '@'; memory[i+1][j] = !memory[i+1][j]; } }if (j - 1 >= 0){ if (computer[i][j-1] != '#'){ computer[i][j-1] = '@'; memory[i][j-1] = !memory[i][j-1]; } }if (j + 1 < n){ if (computer[i][j+1] != '#'){ computer[i][j+1] = '@'; memory[i][j+1] = !memory[i][j+1]; } } } } } }int cnt = 0; for (int i = 0;i < n;i++){ for (int j = 0;j < n;j++){ if (computer[i][j] == '@') cnt++; } }cout << cnt; return 0; }