This question is too difficult to understand the question. It is actually a simple array processing, adding up and down to the left and right, and then adding the obtained value to the current item in the table, if this parameter is exceeded, it is processed.
# 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;
}