Source: Click to open the link
A very good simulation question, it looks complex enough. You must understand the meaning of the question, especially the number of days, which is not directly related to the array. It is only related to the number of DNA updates. This is a day... Orz
You can try the simulation.
# Include <iostream> # include <string> # include <cstring> using namespace STD; int dir [4] [2] = {0,-1}, {0, 1 }, {-}, {}; int mat [20] [20], tar [20] [20], tar2 [20] [20]; char transtar [20] [20]; int pxvalue [16]; int main () {int testcase; CIN> testcase; For (int s = 1; S <= testcase; s ++) {memset (MAT, 0, sizeof (MAT); memset (TAR, 0, sizeof (TAR); memset (pxvalue, 0, sizeof (pxvalue); int day, TMP, tmpx, tmpy; CIN> day; for (INT I = 0; I <16; I ++ ){ Cin> pxvalue [I] ;}for (INT I = 0; I <20; I ++) {for (Int J = 0; j <20; j ++) {CIN> mat [I] [J] ;}}for (int K = 0; k <day; k ++) {for (INT I = 0; I <20; I ++) {for (Int J = 0; j <20; j ++) {TMP = mat [I] [J]; for (INT z = 0; Z <4; Z ++) {tmpx = I + dir [Z] [0]; tmpy = J + dir [Z] [1]; if (tmpx> = 0 & tmpx <20 & tmpy> = 0 & tmpy <20) TMP + = mat [tmpx] [tmpy];} tar [I] [J] = mat [I] [J] + pxvalue [TMP]; If (TAR [I] [J]> 3) tar [I] [J] = 3; if (TAR [I] [J] <0) tar [I] [J] = 0 ;}} memcpy (MAT, tar, sizeof (MAT )); // Rolling update, top priority} For (INT I = 0; I <20; I ++) {for (Int J = 0; j <20; j ++) {If (TAR [I] [J] = 0) {transtar [I] [J] = '. ';} else if (TAR [I] [J] = 1) {transtar [I] [J] = '! ';} Else if (TAR [I] [J] = 2) {transtar [I] [J] = 'X ';} else if (TAR [I] [J] = 3) transtar [I] [J] = '#' ;}} for (INT I = 0; I <20; I ++) {for (Int J = 0; j <20; j ++) {cout <transtar [I] [J] ;}cout <Endl ;} if (s! = Testcase) cout <Endl;} return 0 ;}