首页 > 其他分享 >UVa 457 Linear Cellular Automata (water ver.)

UVa 457 Linear Cellular Automata (water ver.)

时间:2023-04-12 11:40:27浏览次数:41  
标签:DNA Linear density character 457 dish ver line population


457 - Linear Cellular Automata

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=398

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


样例输出没写完,反正输出50行就是。


完整代码:

/*0.012s*/

#include <cstdio>
#include <cstring>

int DNA[10], density[50][45];

int main(void)
{
	int t, i, j;
	scanf("%d", &t);
	while (t--)
	{
		for (i = 0; i < 10; i++)
			scanf("%d", &DNA[i]);
		memset(density, 0, sizeof(density));
		density[0][20] = 1;
		for (i = 1; i < 50; i++)
			for (j = 1; j < 41; j++)
				density[i][j] = DNA[density[i - 1][j - 1] + density[i - 1][j] + density[i - 1][j + 1]];
		for (i = 0; i < 50; i++)
		{
			for (j = 1; j < 41; j++)
			{
				switch (density[i][j])
				{
                    case 0:putchar(' ');break;
                    case 1:putchar('.');break;
                    case 2:putchar('x');break;
                    default:putchar('W');//3
				}
			}
			putchar('\n');
		}
		if (t > 0) putchar('\n');
	}
	return 0;
}



标签:DNA,Linear,density,character,457,dish,ver,line,population
From: https://blog.51cto.com/u_5535544/6185321

相关文章

  • UVa 10783 Odd Sum (water ver.)
    10783-OddSumTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=19&page=show_problem&problem=1724Givenarange [a, b],youaretofindthesummationofalltheoddintegersinthisran......
  • sqlserver 使用脚本创建作业 (by me)
    usemastergo--定义创建作业DECLARE@jobiduniqueidentifier,@jobnamesysnameSET@jobname=N'testInterval'IFEXISTS(SELECT*FROMmsdb.dbo.sysjobsWHEREname=@jobname)EXECmsdb.dbo.sp_delete_job@[email protected]_add_job@job_......
  • 【Serverless】云数据库端云一体化问题
     【关键字】AGC、HarmonyOS、端云一体化 【问题描述】开发者反馈在鸿蒙应用集成了AGC云数据库服务,在引入AGC服务时遇到了一些问题。具体如下所述:1、HarmonyOSArkTS语言开发,参数是number类型,但是查询的云数据库字段是Integer类型,这要怎么处理。2、样例中querybook的字段b......
  • SpringBoot 集成 MybatisPlus 六——ActiveRecord 增、删、改
    1向表中插入记录1.1插入所有列在创建实体对象时,指定所有字段的内容,包括ID列。@TestpublicvoidtestAddUser(){Useruser=newUser(20,"成吉思汗","男","一代天骄");booleanres=user.insert();System.out.println(res);}调用MyBatisPlus时,后台执行的......
  • 第九篇 手写原理代码 - 数组 【 实现 forEach、map、filter、every、some 】
    1、forEachArray.prototype.my_forEach=function(callback){for(leti=0;i<this.length;i++){callback(this[i],i,this);}};2、mapArray.prototype.my_map=function(callback){constarr=[];for(leti=0;i<this.length;......
  • 广州大学第十七届ACM大学生程序设计竞赛 L. 因子模仿 - hard version 线段树维护矩阵
    传送门大致思路:  观察发现,茉美香胜利会叠加对手所有状态,茉美香失败会被对手叠加所有状态。我们可以用矩阵[a1,a2,b1,b2]表示两个人的状态(其中a1,a2表示茉美香,b1,b2表示对手)茉美香赢了之后的状态是[a1+b1,a2+b2,b1,b2],茉美香输了之后的状态是[a1,b1,a1+b1,......
  • DBeaver安装与使用教程(超详细安装与使用教程),好用免费的数据库管理工具
    文章原链接http://t.csdn.cn/Jf4QN       ......
  • Docker CLI docker compose convert常用命令
    Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的Linux或Windows操作系统的机器上,也可以实现虚拟化。Docker是内核虚拟化,不使用Hypervisor是不完全虚拟化,依赖内核的特性实现资源隔离。本文主要介绍DockerCLI中d......
  • sql server 复制添加新表失败
    微软官方对sp_addarticle的解释:Whenyoupublishobjects,theirdefinitionsarecopiedtoSubscribers.Ifyouarepublishingadatabaseobjectthatdependsononeormoreotherobjects,youmustpublishallreferencedobjects.Forexample,ifyoupublishavi......
  • 【一行代码秒上云】Serverless六步构建全栈网站
    摘要:Serverless怎么玩?听一千道一万不如亲手来实践,跟着我们以华为云Serverless实践FunctionGraph来免费体验一下六步构建全栈网站吧前言:Serverless怎么玩?听一千道一万不如亲手来实践,跟着我们以华为云Serverless实践FunctionGraph来免费体验一下六步构建全栈网站吧!五分钟就完成的......