uva 457

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

1

0 1 2 0 1 3 3 2 3 0

Sample Output

bbbbbbbbbbbbbbbbbbb.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".

翻译:

一个生物学家在做细菌的DNA转变试验,对象是在培养皿成直线排列生长的细菌群。通过改变DNA,他能够为细菌设定对旁边培养皿

的细菌密度的反应程式。细菌密度大小用0-3来衡量。DNA信息以细菌密度值的DNA数列表示,编号从0到9。说明如下:

在任一指定培养皿,K是该培养皿、该培养皿最靠近的左边的以及最靠近的右边的细菌密度的值之和为K,则第二天,该培养皿的细菌密度为

DNA[K].

假定一列培养皿中,最左边的培养皿的左边的培养皿的细菌密度为0,最右边的培养皿的右边的培养皿的细菌密度为0。

现在很清楚,一些DNA程式引起所有细菌死亡(如[0,0,0,0,0,0,0,0,0,0]),另一些则引起数量暴增(如

[3,3,3,3,3,3,3,3,3,3])。这个生物学家感兴趣的是其他一些没有那么明显的居中型的DNA程式会有什么结果。

编一程序模仿一列40个培养皿的细菌生长情况,假设20号培养皿开始时的细菌密度为1,而其他培养皿的细菌密度为0。

输入

在一行输入一个正整数,表示下面的个案的数目,每个个案如下所列。这一行后是一空行,而且两个连续的输入之间也有一空行。

每一组输入,你的程序会在一行上显示DNA程式(10个整数数值)

输出

每一个试验案例,输出必须与以下的描述一致。两个连续个案的输出之间有一空行。

每一组输入,应该打进以下50天中每天40个培养皿的细菌密度。每一天的输出应该占据一行40个字符。每一个培养皿由那一行的一

个字符表示。0密度以字符` '表示。1密度以`.'.表示。2密度以`x'表示。`3密度以`W'表示。


#include <stdio.h>
#include <string.h>

int a[50][40];
int main()
{
     int n;
     int i, j;
     int DNA[10];
     scanf("%d", &n);
     while(n--)
     {
          for(i = 0; i < 50; i++)
          {
               memset(a[i], 0, sizeof(a[i]));
          }
          a[0][19] = 1;
          for(i = 0; i < 10; i++)
          {
               scanf("%d", &DNA[i]);
          }
          for(j = 0; j < 40; j++)
          {
               if(j == 19)
               printf(".");
               else
               {
                    printf(" ");
               }
          }
          printf("\n");
          for(i = 1; i < 50; i++)
          {
               for(j = 0; j < 40; j++)
               {
                    if(j == 0)
                    {
                         a[i][j] = a[i-1][j] + a[i-1][j+1];
                    }
                    else if(j == 39)
                    {
                         a[i][j] = a[i-1][j-1] + a[i-1][j];
                    }
                    else
                    {
                         a[i][j] = a[i-1][j-1]+a[i-1][j]+a[i-1][j+1];
                    }
               }
               for(j = 0; j < 40; j++)
               {
                    if(DNA[a[i][j]] == 0)
                    {
                         printf(" ");
                    }
                    else if(DNA[a[i][j]] == 1)
                    {
                         printf(".");
                    }
                    else if(DNA[a[i][j]] == 2)
                    {
                         printf("x");
                    }
                    else if(DNA[a[i][j]] == 3)
                    {
                         printf("W");
                    }
                    a[i][j] = DNA[a[i][j]];
               }
               printf("\n");
          }
          if(n > 0)
          {
               printf("\n");
          }

     }
     return 0;
}

看懂题了就不难了,K是该培养皿、该培养皿最靠近的左边的以及最靠近的右边的细菌密度的值之和为K,则第二天,该培养皿的细菌密度为DNA[K].  主要是把这句话看懂了就OK了


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值