Uva - 457 - Linear Cellular Automata
2013-02-06 21:45
471 查看
先上题目:
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.
ForeachinputsetyourprogramwillreadintheDNAprogram(10integervalues)ononeline.
Foreachinputsetitshouldprintthedensitiesofthe40dishesforeachofthenext50days.Eachday'sprintoutshouldoccupyonelineof40characters.Eachdishisrepresentedbyasinglecharacteronthatline.Zeropopulationdensitiesaretobeprintedasthecharacter`'.Populationdensity1willbeprintedasthecharacter`.'.Populationdensity2willbeprintedasthecharacter`x'.Populationdensity3willbeprintedasthecharacter`W'.
Note:Wheshowonlythefirsttenlinesofoutput(thetotalnumberoflinesmustbe50)andthespaceshavebeenreplacedwiththecharacter"b"foreaseofreading.TheactualoutputfilewillusetheASCII-spacecharacter,not"b".
这一题只要弄懂题意的话就是一题水题。开始题目里面某一些地方看得不是很懂,于是卡了一下,后来经人解释了一下题目的大意,然后就顺畅了。
我的方法是先打印第一行,然后再按照题目的意思进行下面的操作。
这里我是用了两个数组dish1和dish2。前者用来记录上一天40个培养皿的情况,后者用于储存操作后的情况,然后再将其转化为题目要求的符号输出。其中dish2[i]=dish1[i-1]+dish1[i]+dish1[i+1]。值得注的是最左边和最右边两个培养皿是dish2[1]=dish1[1]+dish1[2]以及dish2[40]=dish2[39]+dish2[40]。
为了处理这两个特殊情况,我把dish1和dish2都开大了一点,并且初始化全为0,对数组元素的处理时1<=i<=40。
对于换行问题,按照题目的意思来就没有错了。,只是,在每一行输出以后都要换行。
上代码:
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".
这一题只要弄懂题意的话就是一题水题。开始题目里面某一些地方看得不是很懂,于是卡了一下,后来经人解释了一下题目的大意,然后就顺畅了。
我的方法是先打印第一行,然后再按照题目的意思进行下面的操作。
这里我是用了两个数组dish1和dish2。前者用来记录上一天40个培养皿的情况,后者用于储存操作后的情况,然后再将其转化为题目要求的符号输出。其中dish2[i]=dish1[i-1]+dish1[i]+dish1[i+1]。值得注的是最左边和最右边两个培养皿是dish2[1]=dish1[1]+dish1[2]以及dish2[40]=dish2[39]+dish2[40]。
为了处理这两个特殊情况,我把dish1和dish2都开大了一点,并且初始化全为0,对数组元素的处理时1<=i<=40。
对于换行问题,按照题目的意思来就没有错了。,只是,在每一行输出以后都要换行。
上代码:
#include<stdio.h>
#include<string.h>
intmain()
{
intdna[10],i,n,m,k,dish1[45],dish2[45];
scanf("%d",&n);
while(n--)
{
memset(dish1,0,sizeof(dish1));
memset(dish2,0,sizeof(dish2));
memset(dna,0,sizeof(dna));
dish1[20]=1;
for(i=0;i<10;i++)scanf("%d",&dna[i]);
printf(".\n");
m=49;
k=0;
while(m--)
{
for(i=1;i<=40;i++)
{
k=dish1[i-1]+dish1[i]+dish1[i+1];
dish2[i]=dna[k];
switch(dish2[i])
{
case0:putchar('');break;
case1:putchar('.');break;
case2:putchar('x');break;
case3:putchar('W');break;
}
}
printf("\n");
for(i=1;i<=40;i++)dish1[i]=dish2[i];
}
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
- 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
- uva457 - Linear Cellular Automata
- UVA-457-Linear Cellular Automata
- UVa 457 Linear Cellular Automata (water ver.)
- UVa457 Linear Cellular Automata
- UVa 457 - Linear Cellular Automata
- UVA457 - Linear Cellular Automata
- uva-457-Linear Cellular Automata
- UVa 457 - Linear Cellular Automata
- uva Linear Cellular Automata
- UVaOJ 457 - Linear Cellular Automata