UVa 457 - Linear Cellular Automata
2012-10-28 13:28
417 查看
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".
#include<stdio.h>
#include<string.h>
intis_char(intw[],intt)
{
intflag=w[t];
switch(flag)
{
case0:printf("");break;
case1:printf(".");break;
case2:printf("x");break;
case3:printf("W");break;
default:return-1;
}
}
intmain()
{
intdish[42],DNA[10],dishcpy[42],i,j,n,midl,t,data;
scanf("%d",&n);
for(t=1;t<=n;++t)
{
memset(dish,0,sizeof(dish));
memset(dishcpy,0,sizeof(dish));
dishcpy[20]=dish[20]=1;dish[0]=0;
memset(DNA,0,sizeof(DNA));
for(i=0;i<10;++i)
scanf("%d",&DNA[i]);
for(data=1;data<=50;++data)
{
for(j=1;j<=40;++j)is_char(dishcpy,j);printf("\n");
for(midl=1;midl<=40;++midl)
{
dishcpy[midl]=DNA[(dish[midl-1]+dish[midl]+dish[midl+1])];
}
for(j=1;j<=40;++j)dish[j]=dishcpy[j];
}
if(t!=n)printf("\n");
}
return0;
}
解题报告:
一开始题目长且对题目所指的意思不太明白,DNA序列是你要输入的数据,所指dish的值=DNA中第K个数的值=所指dish细菌浓度+所指dish左边细菌浓度+所指dish右边细菌浓度(0—40)tip:细菌的浓度(0-3表示),最左边的dish假设还有一个浓度为0的dish,同理右边也是如此假设。输出每天dish值的变化,共50天;input中要求输入要输入空格,可以忽略,正是以为要自己输出blankspace弄得我WA了一次,这点教训要谨记!
一开始看不懂follows中的farlefthasleft,忽略后做出来的题目肯定得WA了,二就是对input表示不理解,换行是否要自己输入还是要自己输出,这点完全不确认,所以注定要WA了,三是没看output后面的Note,这点本来不应该的。总来说,英语的理解能力还待提高,耐心还待培养,思维能力还待提高,最重要的还是书要看、题要做!这题涨了点经验了。
相关文章推荐
- 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
- 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 Linear Cellular Automata
- UVaOJ 457 - Linear Cellular Automata