UVA 457Linear Cellular Automata

    xiaoxiao2025-06-11  43

    题目:慢慢读题。

    1.初始时,40个培养皿每一个浓度为 0000000000000000000.00000000000000000000 (字符与整型对应关系:b-0 .-1 x-2 W-3) 输出时,转化为 bbbbbbbbbbbbbbbbbbb.bbbbbbbbbbbbbbbbbbbb (b代表空格) 2.每一个培养皿的下一次浓度(density)= DNA[K],其中K=这一次 这个培养皿的左边那个培养皿 + 这个培养皿本身浓度+这个培养皿右边的培养皿浓度(第一个培养皿左边的培养皿浓度视为0,最后一个培养皿右边的培养皿浓度视为0) 简化理解:k=左+中+右 3.输出50行 4.输入时,第一行指你要输入DNA数组的个数。第二行指DNA数组值。   分析:读懂题后,此题和 杨辉三角 输入输出就很像了。 注意: 题目 看仔细注意力集中 我犯得错误:1.DNA[左中右的和为k] == 下一次浓度 2.初始化 m(循环49次,第一次独立输出) dish[]每轮(n)都要初始化 3.最后一个输出没有换行。

    #include <iostream> #include "cstring" #include <string> #include <stdlib.h> #include <sstream> #include"cstdio" using namespace std; int main() { int n, m; scanf("%d",&n); int dish[45]; int DNA[10]; while(n--) { m=49; memset(dish,0,sizeof(dish)); dish[19]=1; for(int i=0; i<10; i++) cin>>DNA[i]; for(int i=0; i<40; i++) { switch(dish[i]) { case 0:cout<<' ';break; case 1:cout<<'.';break; case 2:cout<<'x';break; case 3:cout<<'W';break; } } cout<<endl; while(m--) { int L=0,P=0; for(int i=0; i<40; i++) { P=dish[i]; if(i==39) dish[i]= DNA[L+0+dish[i]]; else dish[i]=DNA[dish[i+1]+L+dish[i]]; L=P; } for(int i=0; i<40; i++) { switch(dish[i]) { case 0:cout<<' ';break; case 1:cout<<'.';break; case 2:cout<<'x';break; case 3:cout<<'W';break; } } cout<<endl; } if(n) cout<<endl; } return 0; }
    最新回复(0)