457 - Linear Cellular Automata 细胞的线性自动变换机制

来源:互联网 发布:mac快捷键截图 编辑:程序博客网 时间:2024/05/22 12:13

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://DNA信息是由一个DNA数组来表示的,下标0-9.

  • 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].//在每个培养皿中,K=本培养皿的菌落浓度+紧邻的左边一个培养皿的菌落浓度+紧邻的右边一个培养皿的菌落浓度。到了第二天,培养皿中菌落浓度会变成DNA[K],即,该点的值变成了通过DNA序列的一个哈希变换。
  • The dish at the far left of the line is considered to have a left neighbor with population density 0.//说明了最左边的培养皿的浓度,把它的左邻居的培养皿的浓度人工设为了0.
  • The dish at the far right of the line is considered to have a right neighbor with population density 0.//说明了最右边的培养皿的浓度,把它的右邻居的培养皿的浓度人工设为了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]).//看一下这个说明,如果每次算出来的下标无论是什么,算出来下标对应的数组值永远都是0,所以,最后,每个培养皿中的菌落的浓度都会变为0,也就是说的die off灭绝。 Others result in immediate population explosions (e.g., [3,3,3,3,3,3,3,3,3,3]).//同样的,每个算出来的下标对应的值都是3,也很快浓度回答到最大的3.也看到了为什么DNA数组的下标要设置为0-9,因为,其中的自己加上两个相邻,最极端的情况,也就是最大值,也只能是3+3+3=9.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.//初始时的40个培养皿,给的初始条件是第20个的初始浓度为1,其余位置的初始浓度为0.

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

前面做过相关格式的问题,输入时候的空行千万不要用printf("\n")来做强制性要求!!!!!!!否则会出现严重的不知名报错。。。


AC代码为:(偷笑这是我做过最痛快的一次AC,就是因为W是大写的,我写成小写的了WA了一次)

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;


char change(int key)
{
  if(key==0) return ' '; 
  else if(key==1) return '.';
  else if(key==2) return 'x';
  else if(key==3) return 'W';
}


int main()
{
  int casenum;
  int DNA[10];
  int i,j,m,k,num,index;
  scanf("%d",&casenum);//输入规模数
  for(i=0;i<casenum;i++)
  {
    int dishes[50][42]={0};//二维数组元素全部初始化为'0' 
    dishes[0][20]=1;
    for(m=0;m<10;m++)
      scanf("%d",&DNA[m]);//输入DNA序列
    // 初始化40个培养皿,50天的培养时间,第一列跟最后一列为全0,实际应用的为下标从1-40
    for(k=1;k<=40;k++)
printf("%c",change(dishes[0][k]));
    printf("\n");
    for(j=1;j<50;j++)
    { 
      for(k=1;k<=40;k++)
      {
index=dishes[j-1][k]+dishes[j-1][k-1]+dishes[j-1][k+1];
dishes[j][k]=DNA[index];
printf("%c",change(dishes[j][k]));
      }
      printf("\n");
    }
    if(i!=casenum-1)
      printf("\n");
  }
  return 0;
}


原创粉丝点击