UVA 457 - Linear Cellular Automata
来源:互联网 发布:js prop attr 编辑:程序博客网 时间:2024/05/04 11:14
这题没什么好说的
翻译:
有一位生物学家正在进行一项生物实验,他将经过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。
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<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>using namespace std;int grow[42], dna[10], res[42];void init(){ for (int i = 0; i < 42; i++) grow[i] = 0; grow[20] = 1;}void oneday(){ int temp; for (int i = 1; i < 41; i++) //注意边界41 { temp = grow[i] + grow[i-1] + grow[i+1]; res[i] = dna[temp]; }}void print(int grow[]){ for (int i = 1; i < 41; i++) { if (grow[i] == 0) printf(" "); else if (grow[i] == 1) printf("."); else if (grow[i] == 2) printf("x"); else if (grow[i] == 3) printf("W"); } printf("\n");}int main(){ int i, n; //freopen("input.txt","r",stdin); while(scanf("%d",&n) == 1) { while(n--) { for(i = 0; i < 10; i++) { scanf("%d",&dna[i]); } init(); print(grow); for(i = 0; i < 49; i++) { oneday(); memcpy(grow,res,sizeof(grow)); print(grow); } if(n) printf("\n"); } } //freopen("CON","r",stdin); //system("pause"); return 0;}
- UVa 457 - Linear Cellular Automata
- uva-457-Linear Cellular Automata
- UVA 457 - Linear Cellular Automata
- UVA 457 - Linear Cellular Automata
- UVA 457 - Linear Cellular Automata
- uva 457 Linear Cellular Automata
- UVa 457 - Linear Cellular Automata
- UVa 457 - Linear Cellular Automata
- UVA 457 Linear Cellular Automata
- UVA - 457 Linear Cellular Automata
- UVA-457-Linear Cellular Automata
- UVA - 457 Linear Cellular Automata
- uva Linear Cellular Automata
- UVA OJ 457 - Linear Cellular Automata
- UVa 457 Linear Cellular Automata (water ver.)
- UVa - 457 - Linear Cellular Automata 题解
- uva 457 Linear Cellular Automata(模拟)
- UVA - 457 Linear Cellular Automata(水题)
- Lumia 820到手!
- EXTJS4.x之grid(2)--实现添加用户功能
- POJ 1201 Intervals (差分约束)
- linux 删除.svn 目录
- CB上看来的
- UVA 457 - Linear Cellular Automata
- 敏捷开发“松结对编程”系列之十五:L型代码结构(编程篇之一)
- Linux virtual filesystem switch I 磁盘相关概念以及知识
- [ubuntu]修改apt-get 默认源为163.mirror 源
- HDLC协议
- 用scrollerView实现图片的放大缩小
- 数据库事务的处理 (ACID(Atomic/Consistency/Isolation/Durability))
- JS操作JSON
- WINCE串口驱动分析