A biologist is experimenting with DNA modification of bacterial colonies being grown in a linear array of culture dishes. By changing the DNA, he is able ``program" the bacteria to respond to the population density of the neighboring dishes. Population is measured on a four point scale (from 0 to 3). The DNA information is represented as an array DNA, indexed from 0 to 9, of population density values and is interpreted as follows:
Now, clearly, some DNA programs cause all the bacteria to die off (e.g., [0,0,0,0,0,0,0,0,0,0]). Others result in immediate population explosions (e.g., [3,3,3,3,3,3,3,3,3,3]). The biologist is interested in how some of the less obvious intermediate DNA programs might behave. Write a program to simulate the culture growth in a line of 40 dishes, assuming that dish 20 starts with a population density of 1 and all other dishes start with a population density of 0. InputThe input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs. For each input set your program will read in the DNA program (10 integer values) on one line. OutputFor each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line. For each input set it should print the densities of the 40 dishes for each of the next 50 days. Each day's printout should occupy one line of 40 characters. Each dish is represented by a single character on that line. Zero population densities are to be printed as the character ` '. Population density 1 will be printed as the character `.'. Population density 2 will be printed as the character `x'. Population density 3 will be printed as the character `W'. Sample Input1 0 1 2 0 1 3 3 2 3 0 Sample Outputbbbbbbbbbbbbbbbbbbb.bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbb...bbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbb.xbx.bbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbb.bb.bb.bbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbb.........bbbbbbbbbbbbbbbb bbbbbbbbbbbbbb.xbbbbbbbx.bbbbbbbbbbbbbbb bbbbbbbbbbbbb.bbxbbbbbxbb.bbbbbbbbbbbbbb bbbbbbbbbbbb...xxxbbbxxx...bbbbbbbbbbbbb bbbbbbbbbbb.xb.WW.xbx.WW.bx.bbbbbbbbbbbb bbbbbbbbbb.bbb.xxWb.bWxx.bbb.bbbbbbbbbbb Note: Whe show only the first ten lines of output (the total number of lines must be 50) and the spaces have been replaced with the character "b" for ease of reading. The actual output file will use the ASCII-space character, not "b". | ![]() |
题目大意:模拟细菌生长。给定指定数目的培养皿(40个)和 DNA programs(10个),按以下规则生成下一天的培养皿密度:(假设第 n 个培养皿的密度为 D(n))
- K = D(n-1) + D(n) + D(n+1),下一天第 n 个培养皿的密度为 DNA[K]
- 对于第一个培养皿,D(n-1) 取 0
- 对于最后一个培养皿,D(n+1) 取 0
对于每一个 case,需要把往后 50 天的所有培养皿状态都输出来。
对每一个培养皿
- 当密度为 0 时,输出 ' '
- 密度为 1 时,输出 '.'
- 密度为 2 时,输出 'x'
- 密度为 3 时,输出 'W'
#include <stdio.h>
#include <string.h>
int main() {
int t;
int arr[10];
int day[60][50];
while(scanf("%d",&t) != EOF) {
while(t--) {
for(int i = 0; i < 10; i++) {
scanf("%d",&arr[i]);
}
memset(day,0,sizeof(day));
day[0][20] = 1;
for(int i = 1; i <= 50; i++) {
for(int j = 1; j <= 40; j++) {
int tmp = day[i-1][j-1] + day[i-1][j] + day[i-1][j+1];
day[i][j] = arr[tmp];
switch(day[i-1][j]) {
case 0:
printf(" ");
break;
case 1:
printf(".");
break;
case 2:
printf("x");
break;
case 3:
printf("W");
break;
}
}
printf("\n");
}
if(t) {
printf("\n");
}
}
}
return 0;
}