A biologist experimenting with DNA modification of bacteria has found a way to make bacterial colonies sensitive to
Surrounding population density. By changing the DNA, he is able to �� program �� the bacteria to respond to the varying densities in their immediate neighborhood.
The culture dish is a square, divided into 400 smaller squares (20x20 ). population in each small square is measured on a four point scale (from 0 to 3 ). the DNA information is represented as an array D, indexed from 0 to 15, of integer values and is interpreted as follows:
In any given culture dish square, Let k be the sum of that square's density and the densities of the four squares immediately to the left, right, above and below that square (squares outside the dish are considered to have density 0 ). (K is equal to the density of a small square, plus the density of the four Upper and Lower squares) then, by the next day, that dish Square's density will change by d [k] (which may be a positive, negative, or zero value ). (The next day, with the DNA information series D [K], indicates the density after the current square is updated.) The total density cannot, however, exceed 3 nor drop below 0. (3 equals to 3, and 0 if 0 is smaller)
Now, clearly, some DNA programs cause all the bacteria to die off (e.g ., [-3,-3, ��,-3]). others result in immediate population explosions (e.g ., [3, 3, 3, ��, 3]), and others are just plain boring (e.g ., [0, 0, 0]). the biologist is interested in how some of the less obvious DNA programs might behave.
Write a program to simulate the Culture Growth, reading in the number of days to be simulated, the DNA rules, and the initial population densities of the dish.
Input Format:
Input to this program consists of three parts:
1. The first line will contain a single integer denoting the number of days to be simulated.
2. the second line will contain the DNA Rule D as 16 integer values, ordered from D [0] to d [15], separated from one another by one or more blanks. each integer will be in the range-3 �� 3, volume Sive.
3. the remaining twenty lines of input will describe the initial population density in the culture dish. each line describes one row of squares in the culture dish, and will contain 20 integers in the range 0 �� 3, separated from one another by 1 or more blanks.
Output Format:
The program will produce exactly 20 lines of output, describing the population densities in the culture dish at the end of the simulation. each line represents a row of squares in the culture dish, and will consist of 20 characters, plus the usual end-of-line terminator.
Each character will represent the population density at a single dish Square, as follows:
No other characters may appear in the output.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. each input block is in the format indicated in the Problem description. there is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Sample input:
1
2
0 1 1 1 2 1 0-1-1-1-2-2-3-3-3-3
3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sample output:
##!.................
#!..................
!...................
....................
....................
....................
....................
.........!..........
........! #!.........
.......! # X #!........
........! #!.........
.........!..........
....................
....................
....................
....................
....................
....................
....................
....................
// A simple array is used to process the question, that is, the question is not easy to understand. In fact, the main information is what I translated in the second paragraph.
// The following is a problem-solving code, transferred from: http://blog.csdn.net/phinecos/archive/2008/10/23/4612058.aspx
# Include <iostream>
Using namespace STD;
Const int maxnum = 20; // the size of the petri dish is * 20
Char signtable [] = ".! X # "; // symbol table
Int dish [maxnum] [maxnum], Res [maxnum] [maxnum];
Int day, d [16];
Int main ()
{
INT cases; // Number of test samples
Int I, J, K;
While (CIN> Cases)
{
While (cases --)
{
Cin> day; // day of training
// Input the DNA sequence information
For (k = 0; k <16; ++ K)
Cin> d [k];
// Enter the petri dish data
For (I = 0; I <maxnum; ++ I)
For (j = 0; j <maxnum; ++ J)
Cin> dish [I] [J];
While (day --)
{
For (I = 0; I <maxnum; ++ I)
For (j = 0; j <maxnum; ++ J)
{
K = dish [I] [J];
// Combine with upper, lower, and left
If (I-1> = 0)
K + = dish [I-1] [J];
If (I + 1 <maxnum)
K + = dish [I + 1] [J];
If (J-1> = 0)
K + = dish [I] [J-1];
If (J + 1 <maxnum)
K + = dish [I] [J + 1];
Res [I] [J] = dish [I] [J] + d [k];
// Cannot exceed 0 ~ Range 3
If (RES [I] [J]> 3)
Res [I] [J] = 3;
If (RES [I] [J] <0)
Res [I] [J] = 0;
}
Memcpy (dish, res, sizeof (dish ));
}
For (I = 0; I <maxnum; ++ I)
{
For (j = 0; j <maxnum; ++ J)
Cout <signtable [dish [I] [J];
Cout <Endl;
}
// There is an empty line between the samples
If (cases! = 0)
Cout <Endl;
}
}
Return 0;
}