UVa 457 Linear Cellular Automata (water ver.)
2013-09-14 09:27
609 查看
457-LinearCellularAutomata
Timelimit:3.000secondsAbiologistisexperimentingwithDNAmodificationofbacterialcoloniesbeinggrowninalineararrayofculturedishes.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,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.Theactualoutputfile
willusetheASCII-spacecharacter,not"b".
样例输出没写完,反正输出50行就是。
完整代码:
#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;
}
相关文章推荐
- UVa 457 - Linear Cellular Automata
- UVa457 Linear Cellular Automata
- uva-457-Linear Cellular Automata
- UVA 457 - Linear Cellular Automata
- UVa 457 - Linear Cellular Automata
- Uva - 457 - Linear Cellular Automata
- UVa 457 - Linear Cellular Automata
- UVa 457 - Linear Cellular Automata
- 【UVA】【第0章】457 - Linear Cellular Automata
- UVA 457 - Linear Cellular Automata
- UVA - 457 Linear Cellular Automata
- UVA-457-Linear Cellular Automata
- UVA 457 - Linear Cellular Automata
- UVa_457 Linear Cellular Automata
- UVA457 - Linear Cellular Automata
- UVA 457 - Linear Cellular Automata
- uva457 - Linear Cellular Automata
- UVA 457 Linear Cellular Automata
- UVaOJ 457 - Linear Cellular Automata
- UVaOJ 457 - Linear Cellular Automata