Test instructions: Give a number of days n, the change of bacteria in the 20*20 phalanx. Each change plus a d[k],d array has a given number of 16. K is a lattice of it itself plus four numbers up and down about it. Simple simulation questions.
Analysis:
#include <iostream>using namespace Std;int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};char den[]= ". x# "; int d[16];int map[20][20],tmp[20][20];void fun () {int i,j,index,d,x,y;for (i=0;i<20;i++) for (j=0;j<20;j++) { Index=map[i][j];for (d=0;d<4;d++) {x=i+dir[d][0];y=j+dir[d][1];if (x>=0&&x<20&&y>=0 &&Y<20) index+=map[x][y];} Tmp[i][j]=map[i][j]+d[index];if (tmp[i][j]>3) Tmp[i][j]=3;else if (tmp[i][j]<0) tmp[i][j]=0;} for (i=0;i<20;i++) for (j=0;j<20;j++) map[i][j]=tmp[i][j];} int main () {int t,day,i,j,k,t;cin>>t;for (t=1;t<=t;t++) {cin>>day;for (i=0;i<16;i++) cin>>D[i ];for (i=0;i<20;i++) for (j=0;j<20;j++) cin>>map[i][j];for (k=0;k<day;k++) fun (); Impersonation for (i=0;i<20;i++) {for (j=0;j<20;j++) Cout<<den[map[i][j]];cout<<endl;} if (t<t) Cout<<endl;} return 0;}
HDU ACM 1057 A New growth industry simple simulation