Linear Cellular Automata

 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, 1, 2, 3DNA遗传因子可用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

Input

输入的第一列有一个整数表示测试资料的组数,接下来会有一列空行,每 组测试资料之间亦有一列空行。 每组测试资料一列,有10个整数。

Output

请依照下列的说明输出每组测试资料的结果,每组结果之间以一列空行隔开。 请对每组资料输出40个培养皿的细菌密度,连续输出50天,每一天的资料请输出一列40个字元,每个培养皿以一个字元表示,密度为0请输出空白字元,密度为1请输出'.',密度为2请输出'x',密度为3请输出'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

注意:本例输出仅印出前10列,你应该要印出完整的50列。为了方便阅读,本列中的空白字元已经被b所取代,你应该印的是空白字元而非b

#include<stdio.h>
#include<string.h>
main()
{
	int a[50][42],b[10];
	int n,i,j,k,l,p;
	scanf("%d",&n);
	for(p=1;p<=n;p++)
	{
		for(j=0;j<10;j++)
			scanf("%d",&b[j]);
		memset(a, 0, sizeof(int)*50*42);
		a[0][20]=1;
		for(j=1;j<50;j++)
		{
			for(k=1;k<=40;k++)
			{
				l=a[j-1][k]+a[j-1][k-1]+a[j-1][k+1];
				a[j][k]=b[l];
			}
		}
		for(i=0;i<50;i++)
		{
			for(j=1;j<=40;j++)
			{
				switch(a[i][j])
				{
					case 0: printf(" ");break;
					case 1: printf(".");break;
					case 2:  printf("x");break;
					case 3: printf("W");break;
				}
			}
				printf("\n");
		}
		if(p!=n)
		printf("\n");
	}
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值