现在的位置: 首页 > 综合 > 正文

457 – Linear Cellular Automata

2013年01月06日 ⁄ 综合 ⁄ 共 589字 ⁄ 字号 评论关闭

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

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	int cases;
	int dna[10];
	cin >> cases;
	while(cases--)
	{
		int i=0;
		while(i<10)
		{
			cin >> dna[i++];
		}
		int day = 49;
		int arr[45] ;
		memset(arr,0,sizeof(arr));
		arr[20]=1;
		int temp[45];
		cout << "                   .                    \n";
		
		while(day--)
		{
			int j;
			for(j=1;j<=40;j++)
			{
				int k = arr[j-1]+arr[j]+arr[j+1];
				temp[j]=dna[k];
				switch(dna[k])
				{
					case 0 : cout << ' ' ;  break;
					case 1 : cout << '.' ;  break;
					case 2 : cout << 'x' ;  break;
					case 3 : cout << 'W' ;  break;
				}
			}
			cout << endl;
			for(j=1;j<=40;j++)
			{
				arr[j]=temp[j]; 
			}
		}
		if(cases)
			cout << endl;
	}
}

抱歉!评论已关闭.