UVa 457 - Linear Cellular Automata
来源:互联网 发布:福建晨曦软件下载 编辑:程序博客网 时间:2024/05/16 05:56
题目:有40个培养皿,每个培养皿中有一个数字(0-9)。最开始时20号中数字为1,其余为0。
每组输入有一个DNA programs(10个数字构成的序列),它决定每个培养皿下个时间的数字。
设培养皿i中的数字为F(i),则下次其中的数字为DNA(F(i-1)+F(i)+F(i+1))
{即,编号为F(i-1)+F(i)+F(i+1)的DNA programs中对应的数字}。
在给定DNA programs的情况下,输出所有培养皿中从第1-50天的数字。
分析:模拟,dp。读完题目,问题也基本解决了,利用数组储存每天每个编号的培养皿中的数字。
直接按照题意模拟即可。F(i,j)=DNA(F(i-1,j-1)+F(i-1,j)+F(i-1,j+1))
说明:输出0-49天的,不是1-50天的,也不是0-50天的数据。
#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;int DNA[51][42];int MAP[10];int main(){int n;while ( ~scanf("%d",&n) ) for ( int i = 0 ; i < n ; ++ i ) {if ( i ) printf("\n");for ( int j = 0 ; j < 10 ; ++ j )scanf("%d",&MAP[j]);memset( DNA, 0, sizeof(DNA) );DNA[0][20] = 1;for ( int j = 1 ; j < 51 ; ++ j )for ( int k = 1 ; k < 41 ; ++ k )DNA[j][k] = MAP[DNA[j-1][k-1]+DNA[j-1][k]+DNA[j-1][k+1]];for ( int j = 0 ; j < 50 ; ++ j ) {for ( int k = 1 ; k < 41 ; ++ k )switch ( DNA[j][k] ) {case 0 : printf(" ");break;case 1 : printf(".");break;case 2 : printf("x");break;case 3 : printf("W");break;}printf("\n");}}return 0;}
0 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(水题)
- OOP面向对象编程
- 资源管理器空白处右键菜单启动命令提示符
- UVa 409 - Excuses, Excuses!
- 求最大公约数,及最小公倍数。
- C语言标准函数库
- UVa 457 - Linear Cellular Automata
- c++文件操作乱码问题
- Add Two Numbers(LeetCode)
- C语言控制台窗口图形界面编程(四):文本输出
- Cisco 2940交换机电源故障维修
- 怎么做网站推广-网站推广100种方法
- UIRefreshControl iOS6 和 iOS7的风格
- 将对象转换为json字符串
- fedora14 编译arm Linux make menuconfig error处理方法