PrincessTwilightwenttoCelestiaandLuna'soldcastletoresearchthechestfromtheElementsofHarmony.Asequenceofpositiveintegers bi isharmonyifandonlyifforeverytwoelementsofthesequencetheirgreatestcommondivisorequals1.Accordingtoanancientbook,thekeyofthechestisaharmonysequence bi whichminimizesthefollowingexpression:Youaregivensequence ai,helpPrincessTwilighttofindthekey.InputThefirstlinec...
DescriptionBessieandBonniehavefoundatreasurechestfullofmarvelousgoldcoins!Beingcows,though,theycan'tjustwalkintoastoreandbuystuff,soinsteadtheydecidetohavesomefunwiththecoins.TheN(1<=N<=5,000)coins,eachwithsomevalueC_i(1<=C_i<=5,000)areplacedinastraightline.BessieandBonnietaketurns,andforeachcow'sturn,shetakesexactlyonecoinoffofeithertheleftendortherightendoftheline.Thegame...
DescriptionFarmerJohn'scows,pamperedsincebirth,havereachednewheightsoffastidiousness.Theynowrequiretheirbarntobeimmaculate.FarmerJohn,themostobligingoffarmers,hasnochoicebuthiresomeofthecowstocleanthebarn.FarmerJohnhasN(1<=N<=10,000)cowswhoarewillingtodosomecleaning.Becausedustfallscontinuously,thecowsrequirethatthefarmbecontinuouslycleanedduringtheworkday,whichrunsfromsecondnumbe...
DescriptionFarmerJohnhasreturnedtotheCountyFairsohecanattendthespecialevents(concerts,rodeos,cookingshows,etc.).HewantstoattendasmanyoftheN(1<=N<=10,000)specialeventsashepossiblycan.He'srentedabicyclesohecanspeedfromoneeventtothenextinabsolutelynotimeatall(0timeunitstogofromoneeventtothenext!).GivenalistoftheeventsthatFJmightwishtoattend,withtheirstarttimes(1<=T<=100,000)a...
Youhave k piecesoflaundry,eachofwhichyouwanttowash,dryandfold.Youareatalaundromatthathas n1 washingmachines,n2 dryingmachinesand n3 foldingmachines.Eachmachinecanprocessonlyonepieceoflaundryatatime.Youcan'tdryapieceoflaundrybeforeitiswashed,andyoucan'tfolditbeforeitisdried.Moreover,afterapieceoflaundryiswashed,itneedstobeimmediatelymovedintoadryingmachine,andafteritisdried,itneedstobei...
DescriptionThecowsarebuildingarollercoaster!Theywantyourhelptodesignasfunarollercoasteraspossible,whilekeepingtothebudget.TherollercoasterwillbebuiltonalonglinearstretchoflandoflengthL(1<=L<=1,000).TherollercoastercomprisesacollectionofsomeoftheN(1<=N<=10,000)differentinterchangablecomponents.EachcomponentihasafixedlengthWi(1<=Wi<=L).Duetovaryingterrain,eachcomponen...
近期评论