A simple simulation.
Given the number of days N, given d[0]~d[15] given a 20*20 matrix.
Each lattice has a 0~3 number that indicates the number of bacteria.
Every day, each lattice will be added with d[k],k to indicate the sum of the bacteria in the lattice and the adjacent lattice (The matrix is counted as 0, the number of bacteria per cell must not exceed 3, not less than 0).
Ask about the bacterial condition of n days.
1#include <iostream>2#include <cstdio>3 using namespacestd;4 intT,n;5 intd[ -];6 intmap[ -][ -],tmp[ -][ -];7 Chararr[]={'.','!','X','#'};8 intMain ()9 {Tenscanf"%d",&t); One while(t--) A { -scanf"%d",&n); - for(intI=0;i< -; i++) scanf ("%d",&d[i]); the for(intI=0;i< -; i++) - for(intj=0;j< -; j + +) -scanf"%d",&map[i][j]); - intsum; + while(n--) - { + for(intI=0;i< -; i++) A for(intj=0;j< -; j + +) tmp[i][j]=Map[i][j]; at for(intI=0;i< -; i++) - for(intj=0;j< -; j + +) - { -sum=Tmp[i][j]; - if(i>0) sum+=tmp[i-1][j]; - if(i< +) sum+=tmp[i+1][j]; in if(j>0) sum+=tmp[i][j-1]; - if(j< +) sum+=tmp[i][j+1]; tomap[i][j]+=D[sum]; +map[i][j]= map[i][j]>3?3: map[i][j]; -map[i][j]= map[i][j]<0?0: map[i][j]; the } * } $ for(intI=0;i< -; i++)Panax Notoginseng { - for(intj=0;j< -; j + +) thecout<<Arr[map[i][j]]; +cout<<Endl; A } the if(t) puts (""); + } -}
HDU 1057-a New Growth industry