模拟
View Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; #define maxd 20 #define d_length 16 #define dish_side 20 #define maxl 25 int d[maxd]; int n; int dish[2][maxl][maxl]; int dir[5][2] = { { 0, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } }; char table[5] = ".!X#"; void input() { scanf("%d", &n); for (int i = 0; i < d_length; i++) scanf("%d", &d[i]); for (int i = 1; i <= dish_side; i++) for (int j = 1; j <= dish_side; j++) scanf("%d", &dish[0][i][j]); } int cal(int a, int b, int c) { int ret = 0; for (int i = 0; i < 5; i++) ret += dish[a][b + dir[i][0]][c + dir[i][1]]; ret = dish[a][b][c] + d[ret]; if (ret > 3) ret = 3; if (ret < 0) ret = 0; return ret; } void work() { for (int i = 1; i <= n; i++) for (int j = 1; j <= dish_side; j++) for (int k = 1; k <= dish_side; k++) dish[i & 1][j][k] = cal((i & 1) ^ 1, j, k); } void output() { for (int i = 1; i <= dish_side; i++) { for (int j = 1; j <= dish_side; j++) putchar(table[dish[n & 1][i][j]]); puts(""); } } int main() { //freopen("t.txt", "r", stdin); memset(dish, 0, sizeof(dish)); input(); work(); output(); return 0; }