UVa_457 Linear Cellular Automata
2011-07-23 20:47
513 查看
LinearCellularAutomata |
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;
}
相关文章推荐
- UVa 457 Linear Cellular Automata (water ver.)
- UVa457 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
- 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
- uva457 - Linear Cellular Automata
- UVa 457 - Linear Cellular Automata
- UVA-457-Linear Cellular Automata
- 457 - Linear Cellular Automata
- uvaoj 457 - Linear Cellular Automata