您的位置:首页 > 其它

UVa 457 Linear Cellular Automata (water ver.)

2013-09-14 09:27 609 查看


457-LinearCellularAutomata

Timelimit:3.000seconds

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

AbiologistisexperimentingwithDNAmodificationofbacterialcoloniesbeinggrowninalineararrayofculturedishes.BychangingtheDNA,heisable``program"thebacteriatorespondtothepopulationdensity
oftheneighboringdishes.Populationismeasuredonafourpointscale(from0to3).TheDNAinformationisrepresentedasanarrayDNA,indexedfrom0to9,ofpopulationdensityvaluesandisinterpretedasfollows:

Inanygivenculturedish,letKbethesumofthatculturedish'sdensityandthedensitiesofthedishimmediatelytotheleftandthedishimmediatelytotheright.Then,bythenextday,thatdishwillhaveapopulationdensityofDNA[K].
Thedishatthefarleftofthelineisconsideredtohavealeftneighborwithpopulationdensity0.
Thedishatthefarrightofthelineisconsideredtohavearightneighborwithpopulationdensity0.

Now,clearly,someDNAprogramscauseallthebacteriatodieoff(e.g.,[0,0,0,0,0,0,0,0,0,0]).Othersresultinimmediatepopulationexplosions(e.g.,[3,3,3,3,3,3,3,3,3,3]).Thebiologistisinterestedinhowsome
ofthelessobviousintermediateDNAprogramsmightbehave.

Writeaprogramtosimulatetheculturegrowthinalineof40dishes,assumingthatdish20startswithapopulationdensityof1andallotherdishesstartwithapopulationdensityof0.

Input

Theinputbeginswithasinglepositiveintegeronalinebyitselfindicatingthenumberofthecasesfollowing,eachofthemasdescribedbelow.Thislineisfollowedbyablankline,andthereisalsoablankline
betweentwoconsecutiveinputs.
ForeachinputsetyourprogramwillreadintheDNAprogram(10integervalues)ononeline.

Output

Foreachtestcase,theoutputmustfollowthedescriptionbelow.Theoutputsoftwoconsecutivecaseswillbeseparatedbyablankline.
Foreachinputsetitshouldprintthedensitiesofthe40dishesforeachofthenext50days.Eachday'sprintoutshouldoccupyonelineof40characters.Eachdishisrepresentedbyasinglecharacteronthatline.
Zeropopulationdensitiesaretobeprintedasthecharacter`'.Populationdensity1willbeprintedasthecharacter`.'.Populationdensity2willbeprintedasthecharacter`x'.Populationdensity3willbeprintedasthecharacter
`W'.

SampleInput

1

0120133230


SampleOutput

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


Note:Wheshowonlythefirsttenlinesofoutput(thetotalnumberoflinesmustbe50)andthespaceshavebeenreplacedwiththecharacter"b"foreaseofreading.Theactualoutputfile
willusetheASCII-spacecharacter,not"b".

样例输出没写完,反正输出50行就是。

完整代码:

/*0.012s*/

#include<cstdio>
#include<cstring>

intDNA[10],density[50][45];

intmain(void)
{
intt,i,j;
scanf("%d",&t);
while(t--)
{
for(i=0;i<10;i++)
scanf("%d",&DNA[i]);
memset(density,0,sizeof(density));
density[0][20]=1;
for(i=1;i<50;i++)
for(j=1;j<41;j++)
density[i][j]=DNA[density[i-1][j-1]+density[i-1][j]+density[i-1][j+1]];
for(i=0;i<50;i++)
{
for(j=1;j<41;j++)
{
switch(density[i][j])
{
case0:putchar('');break;
case1:putchar('.');break;
case2:putchar('x');break;
default:putchar('W');//3
}
}
putchar('\n');
}
if(t>0)putchar('\n');
}
return0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: