【HDOJ】1057 A New Growth Industry
纯粹的模拟题目。
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 5 #define MAXN 20 6 #define MAXM 16 7 8 char tb[] = ".!X#"; 9 int D[MAXM]; 10 int map[2][MAXN+2][MAXN+1]; 11 int dir[4][2] = { 12 {-1,0}, {1,0}, {0,1}, {0,-1} 13 }; 14 15 int isInvalid(int x, int y) { 16 return x<0 || x>=MAXN || y<0 || y>=MAXN; 17 } 18 19 int main() { 20 int t, n; 21 int i, j, k, p, r; 22 int x, y; 23 int sum; 24 25 #ifndef ONLINE_JUDGE 26 freopen("data.in", "r", stdin); 27 freopen("data.out", "w", stdout); 28 #endif 29 memset(map , 0, sizeof(map)); 30 scanf("%d", &t); 31 while (t--) { 32 scanf("%d", &n); 33 for (i=0; i<MAXM; ++i) 34 scanf("%d", &D[i]); 35 for (r=0, i=1; i<=MAXN; ++i) { 36 for (j=1; j<=MAXN; ++j) { 37 scanf("%d", &map[r][i][j]); 38 } 39 } 40 for (p=0; p<n; ++p, r=!r) { 41 for (i=1; i<=MAXN; ++i) { 42 for (j=1; j<=MAXN; ++j) { 43 sum = map[r][i][j] + map[r][i+1][j] + map[r][i-1][j]+\ 44 map[r][i][j+1] + map[r][i][j-1]; 45 map[!r][i][j] = map[r][i][j] + D[sum]; 46 if (map[!r][i][j] > 3) 47 map[!r][i][j] = 3; 48 if (map[!r][i][j] < 0) 49 map[!r][i][j] = 0; 50 } 51 } 52 } 53 for (i=1; i<=MAXN; ++i) { 54 for (j=1; j<=MAXN; ++j) { 55 printf("%c", tb[map[r][i][j]]); 56 } 57 printf("\n"); 58 } 59 if (t) 60 printf("\n"); 61 } 62 63 return 0; 64 }