您的位置:首页 > 其它

UVa_457 Linear Cellular Automata

2011-07-23 20:47 513 查看
LinearCellularAutomata
AbiologistisexperimentingwithDNAmodificationofbacterialcoloniesbeinggrowninalineararrayofculturedishes.BychangingtheDNA,heisable``program"thebacteriatorespondtothepopulationdensityoftheneighboringdishes.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]).ThebiologistisinterestedinhowsomeofthelessobviousintermediateDNAprogramsmightbehave.

Writeaprogramtosimulatetheculturegrowthinalineof40dishes,assumingthatdish20startswithapopulationdensityof1andallotherdishesstartwithapopulationdensityof0.

Input

Theinputbeginswithasinglepositiveintegeronalinebyitselfindicatingthenumberofthecasesfollowing,eachofthemasdescribedbelow.Thislineisfollowedbyablankline,andthereisalsoablanklinebetweentwoconsecutiveinputs.

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.TheactualoutputfilewillusetheASCII-spacecharacter,not"b".

看了俩小时,愣是没看懂啥意思,看来还是英语太差了!!!

ViewCode

#include<stdio.h>
#include<string.h>

intmain()
{
intn,i,j,k;
scanf("%d",&n);
for(i=0;i<n;i++)
{
intpre[50]={0},cur[50]={0},temp,dic[10];
cur[20]=1;
for(j=0;j<10;j++)
{
scanf("%d",&dic[j]);

}
for(j=0;j<50;j++)
{
for(k=1;k<=40;k++)
{
if(cur[k]==0)printf("");
elseif(cur[k]==1)printf(".");
elseif(cur[k]==2)printf("x");
elseprintf("W");
}
printf("\n");
memcpy(pre,cur,sizeof(pre));
for(k=1;k<=40;k++)
{
temp=pre[k]+pre[k-1]+pre[k+1];
cur[k]=dic[temp];
}
}
if(i!=n-1)printf("\n");
}
return0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: