LittleChrisknowsthere'snofuninplayingdominoes,hethinksit'stoorandomanddoesn'trequireskill.Instead,hedecidedtoplay with thedominoesandmakea"dominoshow".Chrisarranges n dominoesinaline,placingeachpieceverticallyupright.Inthebeginning,hesimultaneouslypushessomeofthedominoeseithertotheleftortotheright.However,somewherebetweeneverytwodominoespushedinthesamedirectionthereisatleastonedominopush...
LittleChrisisboredduringhisphysicslessons(tooeasy),sohehasbuiltatoyboxtokeephimselfoccupied.Theboxisspecial,sinceithastheabilitytochangegravity.Thereare n columnsoftoycubesintheboxarrangedinaline.The i-thcolumncontains ai cubes.Atfirst,thegravityintheboxispullingthecubesdownwards.WhenChrisswitchesthegravity,itbeginstopullallthecubestotherightsideofthebox.Thefigureshowstheinitialandfi...
Description2021.MovingPebblesTwoplayersplaythefollowinggame.Atthebeginningofthegametheystartwithn(1<=n<=100000)pilesofstones.Ateachstepofthegame,theplayerchoosesapileandremoveatleastonestonefromthispileandmovezeroormorestonesfromthispiletoanyotherpilethatstillhasstones.Aplayerlosesifhehasnomorepossiblemoves.Giventheinitialpiles,determinewhowins:thefirstplayer,orthesecondplayer,ifboth...
DescriptionACompilerMystery:WearegivenaC-languagestyleforloopoftype [crayon-6848d3f0ee920337770722/]I.e.,aloopwhichstartsbysettingvariabletovalueAandwhilevariableisnotequaltoB,repeatsstatementfollowedbyincreasingthevariablebyC.WewanttoknowhowmanytimesdoesthestatementgetexecutedforparticularvaluesofA,BandC,assumingthatallarithmeticsiscalculatedinak-bitunsignedintegertype(withvalu...
DescriptionAcm,atreasure-explorer,isexploringagain.Thistimeheisinaspecialmaze,inwhichtherearesomedoors(atmost5doors,representedby'A','B','C','D','E'respectively).Inordertofindthetreasure,Acmmayneedtoopendoors.However,toopenadoorheneedstofindallthedoor'skeys(atleastone)inthemazefirst.Forexample,ifthereare3keysofDoorA,toopenthedoorheshouldfindallthe3keysfirst(that'sthree'a'swhichdenote...
DescriptionBuffaloBillwishestocrossa1000x1000squarefield.Anumberofsnakesareonthefieldatvariouspositions,andeachsnakecanstrikeaparticulardistanceinanydirection.CanBillmakethetripwithoutbeingbitten?InputAssumethatthesouthwestcornerofthefieldisat(0,0)andthenorthwestcornerat(0,1000).Theinputconsistsofalinecontainingn<=1000,thenumberofsnakes.Alinefollowsforeachsnake,containingthreerealnumb...
DescriptionAprefixofastringisasubstringstartingatthebeginningofthegivenstring.Theprefixesof"carbon"are:"c","ca","car","carb","carbo",and"carbon".Notethattheemptystringisnotconsideredaprefixinthisproblem,buteverynon-emptystringisconsideredtobeaprefixofitself.Ineverydaylanguage,wetendtoabbreviatewordsbyprefixes.Forexample,"carbohydrate"iscommonlyabbreviatedby"carb".Inthisproblem,givenasetofwo...
近期评论