DescriptionThecowshavebeensentonamissionthroughspacetoacquireanewmilkingmachinefortheirbarn.TheyareflyingthroughaclusterofstarscontainingN(1<=N<=50,000)planets,eachwithatradingpost.ThecowshavedeterminedwhichofK(1<=K<=1,000)typesofobjects(numbered1..K)eachplanetintheclusterdesires,andwhichproductstheyhavetotrade.Noplanethasdevelopedcurrency,sotheyworkunderthebartersystem:alltr...
PrincessTwilightwenttoCelestiaandLuna'soldcastletoresearchthechestfromtheElementsofHarmony.Asequenceofpositiveintegers bi isharmonyifandonlyifforeverytwoelementsofthesequencetheirgreatestcommondivisorequals1.Accordingtoanancientbook,thekeyofthechestisaharmonysequence bi whichminimizesthefollowingexpression:Youaregivensequence ai,helpPrincessTwilighttofindthekey.InputThefirstlinec...
TwilightSparklewasplayingLudowithherfriendsRainbowDash,AppleJackandFlutterShy.Butshekeptlosing.Havingreturnedtothecastle,TwilightSparklebecameinterestedinthedicethatwereusedinthegame.Thedicehas m faces:thefirstfaceofthedicecontainsadot,thesecondonecontainstwodots,andsoon,the m-thfacecontains m dots.TwilightSparkleissurethatwhenthediceistossed,eachfaceappearswithprobability .A...
Oneday,TwilightSparkleisinterestedinhowtosortasequenceofintegers a1, a2, ..., an innon-decreasingorder.Beingayoungunicorn,theonlyoperationshecanperformisaunitshift.Thatis,shecanmovethelastelementofthesequencetoitsbeginning:a1, a2, ..., an → an, a1, a2, ..., an - 1.HelpTwilightSparkletocalculate:whatistheminimumnumberofoperationsthatsheneedstosortthesequence?InputThefirst...
TwilightSparkleoncegotacrystalfromtheCrystalMine.Acrystalofsize n (n isodd; n > 1)isan n × n matrixwithadiamondinscribedintoit.Youaregivenanoddinteger n.Youneedtodrawacrystalofsize n.Thediamondcellsofthematrixshouldberepresentedbycharacter"D".Allothercellsofthematrixshouldberepresentedbycharacter"*".Lookattheexamplestounderstandwhatyouneedtodraw.InputTheonlylinecontain...
DescriptionThereisanappletreeoutsideofkaka'shouse.Everyautumn,alotofappleswillgrowinthetree.Kakalikesappleverymuch,sohehasbeencarefullynurturingthebigappletree.ThetreehasNforkswhichareconnectedbybranches.Kakanumberstheforksby1toNandtherootisalwaysnumberedby1.Appleswillgrowontheforksandtwoapplewon'tgrowonthesamefork.kakawantstoknowhowmanyapplesarethereinasub-tree,forhisstudyoftheproduceabi...
近期评论