UVa 457 Linear Cellular Automata(线性细胞自动机)

来源:互联网 发布:qq三国转职js转什么好 编辑:程序博客网 时间:2024/05/19 21:58

Linear Cellular Automata 

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:

  • In any given culture dish, let K be the sum of that culture dish's density and the densities of the dish immediately to the left and the dish immediately to the right. Then, by the next day, that dish will have a population density of DNA[K].
  • The dish at the far left of the line is considered to have a left neighbor with population density 0.
  • The dish at the far right of the line is considered to have a right neighbor with population density 0.

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.

Input

The 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.

Output

For 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 Input

10 1 2 0 1 3 3 2 3 0

Sample Output

bbbbbbbbbbbbbbbbbbb.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.xbx.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.bb.bb.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.........bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.xbbbbbbbx.bbbbbbbbbbbbbbbbbbbbbbbbbbbb.bbxbbbbbxbb.bbbbbbbbbbbbbbbbbbbbbbbbbb...xxxbbbxxx...bbbbbbbbbbbbbbbbbbbbbbbb.xb.WW.xbx.WW.bx.bbbbbbbbbbbbbbbbbbbbbb.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".

Linear Cellular Automata 

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:

  • In any given culture dish, let K be the sum of that culture dish's density and the densities of the dish immediately to the left and the dish immediately to the right. Then, by the next day, that dish will have a population density of DNA[K].
  • The dish at the far left of the line is considered to have a left neighbor with population density 0.
  • The dish at the far right of the line is considered to have a right neighbor with population density 0.

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.

Input

The 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.

Output

For 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 Input

10 1 2 0 1 3 3 2 3 0

Sample Output

bbbbbbbbbbbbbbbbbbb.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.xbx.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.bb.bb.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.........bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.xbbbbbbbx.bbbbbbbbbbbbbbbbbbbbbbbbbbbb.bbxbbbbbxbb.bbbbbbbbbbbbbbbbbbbbbbbbbb...xxxbbbxxx...bbbbbbbbbbbbbbbbbbbbbbbb.xb.WW.xbx.WW.bx.bbbbbbbbbbbbbbbbbbbbbb.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".


题目解析:

这道题看了好久,请来英语很好的同学帮忙翻译也没怎么看懂,只得自己逐字逐句地翻译,然后看了下别人的题解才终于恍然大悟。

实际上这道题目不难,只是英语水平需要提高!

先看一下下面的翻译:


翻译 :
有一位生物学家正在进行一项生物实验,他将经过DNA修改的细菌培养在一群线性的培养皿阵列上,通过修改细菌的DNA,他可控制细菌对邻近培养皿上细菌的密度作出反应。密度值分为四个级距:0, 1, 2, 3。DNA遗传因子可用10个整数表示,每个整数的编号分别为0~9,整数代表的是密度值,写成DNA(x),说明如下:
· 对于任何一个培养皿,令K为该培养皿的密度与其邻近两个培养皿密度的和,隔天该培养皿上的细菌密度变为DNA(K)。 
· 培养皿阵列最右边的培养皿,其右边的培养皿密度定义为0。 
· 培养皿阵列最左边的培养皿,其左边的培养皿密度定义为0。 

通过改变DNA,生物学家可使所有细菌最终都死掉(例如: DNA[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),或是使细菌大量生长(例如: DNA[3, 3, 3, 3, 3, 3, 3, 3, 3, 3])。 请你写一个程式来模拟40个培养皿上细菌的生长情况,假设第20个培养皿的细菌初始密度为1,其他培养皿皆为0。
输入
输入的第一列有一个整数表示测试资料的组数,接下来会有一列空行,每 组测试资料之间亦有一列空行。 每组测试资料一列,有10个整数。
输出
请依照下列的说明输出每组测试资料的结果,每组结果之间以一列空行隔开。 请对每组资料输出40个培养皿的细菌密度,连续输出50天,每一天的资料请输出一列40个字元,每个培养皿以一个字元表示,密度为0请输出空白字元,密度为1请输出'.',密度为2请输出'x',密度为3请输出'W'。


解析:

先打印第一行----->"                   .                    ";

     接下来按照题意:

第i个培养皿等于第i-1,i,i+1培养皿之和,密度值为dna[tmp];

tmp = dens1[j-1]+dens1[j]+dens1[j+1];
                dens2[j] = dna[tmp];

最左边和最右边的培养皿是两个培养皿之和,但是我们可以将数组开大些并初始化为0,那么也可以使用上述的公式!

注意:最后的输出,最后一个case后面没有空行。另外,本题输出的‘b’应该是空格(‘ ’),和 414 Machined Surfaces相似!


/*给个样例做对拍:输入:20 1 2 0 1 3 3 2 3 00 1 2 0 1 3 3 2 3 0输出:                   .                                      ...                                    .x x.                                  .  .  .                                .........                              .x       x.                            .  x     x  .                          ...xxx   xxx...                        .x .WW.x x.WW. x.                      .   .xxW . Wxx.   .                    ... . WxW...WxW . ...                  .x xx..WWWW WWWW..xx x.                .  ..W.Wx  WWW  xW.W..  .              ....xWWxWWx W W xWWxWWx....            .x  .WWWWWWWW W WWWWWWWW.  x.          .  x..x      WW WW      x..x  .        ...x .. x     WWWWW     x .. x...      .x .  xx xx    W   W    xx xx  . x.    .   ..x.....x           x.....x..   .  ... .x...   . x         x .   ...x. ... x xx .. x. .. xx       xx .. .x .. xx x.x... xx   xxx ..x     x.. xxx   xx ...   . x ..x x.W. x. x   x .x .W.x x.. x x. .. x x. . WW.    xx xx    .WW . .x x.  .xx x.  x..Wx..  x.....x  ..xW..x  .  ......  .x .WWW.x.x .   . x.x.WWW. x....x xx x..   .x xW.W  .. ..  W.Wx x.  .  . .xx. .x. .  .WWx. .xxxxx. .xWW.  ......x    x . x....xWW x WWWWW x WWx...x    . x  xx .  .  .WWWWxWW   WWxWWWW. . x  .. xxx.. .......x  WWWW   WWWW  x.x. xx.xx .. .xxx     . x W  W   W  W x W.  .WWW. xx. WW.x   .. xW           WxW.....x x. ....WxW x .xx WW           WWWW   . .  xxxxWWWWWx  W.WWW           W  W  ..x..x.W.WW   WWx .xx W                .x.....WW.WW   WWW  W.W                . ..   Wxx.WW   W W  .x.               ..xxx.  WxW WW    W  . . .             .x.WWW . WWW WW      ..x.x..           . .Wx W...W W WW     .x..W..x.         ..x.WWW.W W.W  WW    . ..WWW.. .       .x..Wx xx.W.x.  WW   ..xxWx xWxx..     . ..WWW..WWWW. . WW  .x.WxxW.WxxW.x.   ..xxWx xWWx  x.x..WW . .WWxxWxWxxWW. . .x.WxxW.WWWWxx W..xWW..x.xWxxxWxxxWx.x.x .WWxxWxx  Wx.W.W. WxW..WWxxWxxxWxxWW.W  .xWxxxx.x WWWWxW..WWWWWxWxxxxWxxxxWxx. . WxxWWWW WW  WWWWxW   WWxxWWxxxWWxxxW x..WxxW  WWWW  W  WW    WWxxWWxWxWWxWxWW .WWxxW  W  W     WW                   .                                      ...                                    .x x.                                  .  .  .                                .........                              .x       x.                            .  x     x  .                          ...xxx   xxx...                        .x .WW.x x.WW. x.                      .   .xxW . Wxx.   .                    ... . WxW...WxW . ...                  .x xx..WWWW WWWW..xx x.                .  ..W.Wx  WWW  xW.W..  .              ....xWWxWWx W W xWWxWWx....            .x  .WWWWWWWW W WWWWWWWW.  x.          .  x..x      WW WW      x..x  .        ...x .. x     WWWWW     x .. x...      .x .  xx xx    W   W    xx xx  . x.    .   ..x.....x           x.....x..   .  ... .x...   . x         x .   ...x. ... x xx .. x. .. xx       xx .. .x .. xx x.x... xx   xxx ..x     x.. xxx   xx ...   . x ..x x.W. x. x   x .x .W.x x.. x x. .. x x. . WW.    xx xx    .WW . .x x.  .xx x.  x..Wx..  x.....x  ..xW..x  .  ......  .x .WWW.x.x .   . x.x.WWW. x....x xx x..   .x xW.W  .. ..  W.Wx x.  .  . .xx. .x. .  .WWx. .xxxxx. .xWW.  ......x    x . x....xWW x WWWWW x WWx...x    . x  xx .  .  .WWWWxWW   WWxWWWW. . x  .. xxx.. .......x  WWWW   WWWW  x.x. xx.xx .. .xxx     . x W  W   W  W x W.  .WWW. xx. WW.x   .. xW           WxW.....x x. ....WxW x .xx WW           WWWW   . .  xxxxWWWWWx  W.WWW           W  W  ..x..x.W.WW   WWx .xx W                .x.....WW.WW   WWW  W.W                . ..   Wxx.WW   W W  .x.               ..xxx.  WxW WW    W  . . .             .x.WWW . WWW WW      ..x.x..           . .Wx W...W W WW     .x..W..x.         ..x.WWW.W W.W  WW    . ..WWW.. .       .x..Wx xx.W.x.  WW   ..xxWx xWxx..     . ..WWW..WWWW. . WW  .x.WxxW.WxxW.x.   ..xxWx xWWx  x.x..WW . .WWxxWxWxxWW. . .x.WxxW.WWWWxx W..xWW..x.xWxxxWxxxWx.x.x .WWxxWxx  Wx.W.W. WxW..WWxxWxxxWxxWW.W  .xWxxxx.x WWWWxW..WWWWWxWxxxxWxxxxWxx. . WxxWWWW WW  WWWWxW   WWxxWWxxxWWxxxW x..WxxW  WWWW  W  WW    WWxxWWxWxWWxWxWW .WWxxW  W  W     WW*/#include <stdio.h>#include <stdlib.h>int main(){    int T;    int i, j, tmp;    int dna[10];    int dens1[42], dens2[42];    scanf("%d", &T);    while(T--){        for(i = 0; i<10; i++)            scanf("%d", &dna[i]);        memset(dens1, 0, sizeof(dens1));        memset(dens2, 0, sizeof(dens2));        dens2[20] = 1;        dens1[20] = 1;        for(i = 0; i<50; i++){            for(j = 1; j<=40; j++){                switch(dens2[j]){                    case 0:printf(" ");break;                    case 1:printf(".");break;                    case 2:printf("x");break;                    case 3:printf("W");break;                }                tmp = dens1[j-1]+dens1[j]+dens1[j+1];                dens2[j] = dna[tmp];            }            printf("\n");            for(j = 1; j<=40; j++)                dens1[j] = dens2[j];        }        if(T)   printf("\n");    }    return 0;}

原创粉丝点击