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