//408K 16MS G++
#include <cstdio>
#include <cstring>
using namespace std;
int dish[20][20];
int K[20][20];
int D[16];
int days;
int getDensitySum(int rowId, int columnId) {
int K = 0;
K += dish[rowId][columnId];
if (rowId > 0) {
K += dish[rowId-1][columnId];
}
if (rowId < 19) {
K += dish[rowId+1][columnId];
}
if (columnId > 0) {
K += dish[rowId][columnId - 1];
}
if (columnId < 19) {
K += dish[rowId][columnId + 1];
}
return K;
}
void simulate() {
for (int rowId = 0; rowId < 20; rowId++) {
for (int columnId = 0; columnId < 20; columnId++) {
K[rowId][columnId] = getDensitySum(rowId, columnId);
}
}
for (int rowId = 0; rowId < 20; rowId++) {
for (int columnId = 0; columnId < 20; columnId++) {
dish[rowId][columnId] += D[K[rowId][columnId]];
if (dish[rowId][columnId] > 3) {
dish[rowId][columnId] = 3;
} else if (dish[rowId][columnId] < 0) {
dish[rowId][columnId] = 0;
}
}
}
}
void solve() {
for (int i = 1; i <= days; i++) {
simulate();
}
for (int rowId = 0; rowId < 20; rowId++) {
for (int columnId = 0; columnId < 20; columnId++) {
char c = '.';
if (dish[rowId][columnId] == 1) {
c = '!';
} else if (dish[rowId][columnId] == 2) {
c = 'X';
} else if (dish[rowId][columnId] == 3) {
c = '#';
}
if (columnId < 19) {
printf("%c", c);
} else if (columnId == 19) {
printf("%c\n", c);
}
}
}
}
int main() {
scanf("%d", &days);
for (int i = 0; i < 16; i++) {
scanf("%d", &D[i]);
}
for (int rowId = 0; rowId < 20; rowId++) {
for (int columnId = 0; columnId < 20; columnId++) {
scanf("%d", &dish[rowId][columnId]);
}
}
solve();
}
模拟水题,注意最后输出格子之间是没有空格.