Problem Description:
网络异常,图片无法展示|A biologist experimenting with DNA modification of bacteria has found a way to make bacterial colonies sensitive to the
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). 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 total density cannot, however, exceed 3 nor drop below 0.
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:
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, inclusive.
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:
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.
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 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
Sample Output:
##!.................
#!..................
!...................
....................
....................
....................
....................
.........!..........
........!#!.........
.......!#X#!........
........!#!.........
.........!..........
....................
....................
....................
....................
....................
....................
....................
....................
题目翻译:
培养皿为正方形,分为400个较小的正方形(20x20)。每个小方块中的人口均以四点制(从0到3)进行度量。 DNA信息表示为从0到15的整数D数组D,其解释如下:
在任何给定的培养皿正方形中,令K为该正方形的密度与紧接在该正方形的左,右,上和下四个正方形的密度之和(培养皿外部的正方形被视为密度为0)。然后,到第二天,该菜方的密度将改变D [K](可以是正值,负值或零值)。但是,总密度不能超过3,也不能低于0。
现在,很明显,某些DNA程序会导致所有细菌死亡(例如[-3,-3,…,-3])。其他导致人口激增(例如[3,3,3,…,3]),而其他则只是无聊(例如[0,0,…0])。生物学家对一些不太明显的DNA程序如何表现很感兴趣。
编写一个模拟培养物生长的程序,读取要模拟的天数,DNA规则和培养皿的初始种群密度。
该程序的输入包括三个部分:
第一行将包含一个整数,该整数表示要模拟的天数。
2.第二行将包含DNA规则D,为16个整数值,从D [0]到D [15]排序,彼此隔开一个或多个空格。每个整数将在-3…3(含)范围内。
3.其余的20行输入将描述培养皿中的初始种群密度。每行描述培养皿中的一排正方形,将包含20个整数,范围为0…3,彼此之间用1个或多个空白隔开。
该程序将精确地产生20行输出,在模拟结束时描述培养皿中的种群密度。每行代表培养皿中的一行正方形,将由20个字符以及通常的行结束符组成。
每个字符将代表一个菜盘上的人口密度,如下所示:输出中不能出现其他字符。
程序代码:
#include<stdio.h> #include<string.h> int arr[22][22],temp[22][22],d[17]; char sign[]={'.','!','X','#'}; int main() { int t,n,k; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=0;i<16;i++) scanf("%d",&d[i]); for(int i=1;i<21;i++) for(int j=1;j<21;j++) scanf("%d",&arr[i][j]); while(n--) { for(int i=1;i<21;i++) for(int j=1;j<21;j++) { k=arr[i][j]+arr[i][j-1]+arr[i][j+1]+arr[i-1][j]+arr[i+1][j]; temp[i][j]=arr[i][j]+d[k]; if(temp[i][j]<0) temp[i][j]=0; else if(temp[i][j]>3) temp[i][j]=3; } for(int i=1;i<21;i++) for(int j=1;j<21;j++) arr[i][j]=temp[i][j]; } for(int i=1;i<21;i++) { for(int j=1;j<21;j++) printf("%c",sign[arr[i][j]]); printf("\n"); } if(t) printf("\n"); } return 0; }