457 - Linear Cellular Automata
2014-02-24 17:16
387 查看
LinearCellularAutomata
AbiologistisexperimentingwithDNAmodificationofbacterialcoloniesbeinggrowninalineararrayofculturedishes.BychangingtheDNA,heisable``program"thebacteriatorespondtothepopulationdensityoftheneighboringdishes.Populationismeasuredon
afourpointscale(from0to3).TheDNAinformationisrepresentedasanarray
DNA,indexedfrom0to9,ofpopulationdensityvaluesandisinterpretedasfollows:
Inanygivenculturedish,letKbethesumofthatculturedish'sdensityandthedensitiesofthedishimmediatelytotheleftandthedishimmediatelytotheright.Then,bythenextday,thatdishwillhaveapopulationdensityof
DNA[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]).ThebiologistisinterestedinhowsomeofthelessobviousintermediateDNAprograms
mightbehave.
Writeaprogramtosimulatetheculturegrowthinalineof40dishes,assumingthatdish20startswithapopulationdensityof1andallotherdishesstartwithapopulationdensityof0.
ForeachinputsetyourprogramwillreadintheDNAprogram(10integervalues)ononeline.
Foreachinputsetitshouldprintthedensitiesofthe40dishesforeachofthenext50days.Eachday'sprintoutshouldoccupyonelineof40characters.Eachdishisrepresentedbyasinglecharacteronthatline.Zeropopulationdensitiesaretobeprinted
asthecharacter`'.Populationdensity1willbeprintedasthecharacter`.'.Populationdensity2willbeprintedasthecharacter`x'.Populationdensity3willbeprintedasthecharacter`W'.
Note:Wheshowonlythefirsttenlinesofoutput(thetotalnumberoflinesmustbe50)andthespaceshavebeenreplacedwiththecharacter
"b"foreaseofreading.TheactualoutputfilewillusetheASCII-spacecharacter,not
"b".
AbiologistisexperimentingwithDNAmodificationofbacterialcoloniesbeinggrowninalineararrayofculturedishes.BychangingtheDNA,heisable``program"thebacteriatorespondtothepopulationdensityoftheneighboringdishes.Populationismeasuredon
afourpointscale(from0to3).TheDNAinformationisrepresentedasanarray
DNA,indexedfrom0to9,ofpopulationdensityvaluesandisinterpretedasfollows:
Inanygivenculturedish,letKbethesumofthatculturedish'sdensityandthedensitiesofthedishimmediatelytotheleftandthedishimmediatelytotheright.Then,bythenextday,thatdishwillhaveapopulationdensityof
DNA[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]).ThebiologistisinterestedinhowsomeofthelessobviousintermediateDNAprograms
mightbehave.
Writeaprogramtosimulatetheculturegrowthinalineof40dishes,assumingthatdish20startswithapopulationdensityof1andallotherdishesstartwithapopulationdensityof0.
Input
Theinputbeginswithasinglepositiveintegeronalinebyitselfindicatingthenumberofthecasesfollowing,eachofthemasdescribedbelow.Thislineisfollowedbyablankline,andthereisalsoablanklinebetweentwoconsecutiveinputs.ForeachinputsetyourprogramwillreadintheDNAprogram(10integervalues)ononeline.
Output
Foreachtestcase,theoutputmustfollowthedescriptionbelow.Theoutputsoftwoconsecutivecaseswillbeseparatedbyablankline.Foreachinputsetitshouldprintthedensitiesofthe40dishesforeachofthenext50days.Eachday'sprintoutshouldoccupyonelineof40characters.Eachdishisrepresentedbyasinglecharacteronthatline.Zeropopulationdensitiesaretobeprinted
asthecharacter`'.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".
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
intdish[42],temp[42];
voidprint(){
inti;
for(i=1;i<=40;++i)
{
switch(dish[i])
{
case0:printf("");break;
case1:printf(".");break;
case2:printf("x");break;
case3:printf("W");break;
}
}
printf("\n");
}
intmain(){
intDNA[10],SIZE=sizeof(dish);
intN,i,j;
scanf("%d",&N);
while(N--){
for(i=0;i<10;++i)
scanf("%d",&DNA[i]);
for(i=0;i<=41;++i)
dish[i]=0;
dish[20]=1;
for(i=1;i<=50;++i)
{
print();
for(j=1;j<=40;++j)
temp[j]=DNA[dish[j]+dish[j-1]+dish[j+1]];
memcpy(dish,temp,SIZE);
}
if(N)//必不可少
printf("\n");
}
return0;
}
相关文章推荐
- UVA 457 - Linear Cellular Automata
- UVa 457 - Linear Cellular Automata
- UVa 457 - Linear Cellular Automata
- UVa 457 - Linear Cellular Automata
- uva457 - Linear Cellular Automata
- 457 - Linear Cellular Automata
- UVaOJ 457 - Linear Cellular Automata
- UVa_457 Linear Cellular Automata
- UVA 457 - Linear Cellular Automata
- UVA 457 - Linear Cellular Automata
- UVA457 - Linear Cellular Automata
- 457 - Linear Cellular Automata
- UVA - 457 Linear Cellular Automata
- uvaoj 457 - Linear Cellular Automata
- uva-457-Linear Cellular Automata
- UVA 457 - Linear Cellular Automata
- UVa457 Linear Cellular Automata
- 457 - Linear Cellular Automata
- UVaOJ 457 - Linear Cellular Automata
- Uva - 457 - Linear Cellular Automata