Prof.Vasechkinwantstorepresentpositiveinteger n asasumofaddends,whereeachaddendsisanintegernumbercontainingonly1s.Forexample,hecanrepresent121as121=111+11+–1.Helphimtofindtheleastnumberofdigits 1 insuchsum.InputThefirstlineoftheinputcontainsinteger n (1 ≤ n < 1015).OutputPrintexpectedminimalnumberofdigits 1.Sampletest(s)input[crayon-687dac4c0134d158859393/]output[crayon-68...
Petyahas k matches,placedin n matchboxeslyinginalinefromlefttoright.Weknowthat k isdivisibleby n.Petyawantsallboxestohavethesamenumberofmatchesinside.Forthat,hecanmoveamatchfromitsboxtotheadjacentoneinonemove.Howmanysuchmovesdoesheneedtoachievethedesiredconfiguration?InputThefirstlinecontainsinteger n (1 ≤ n ≤ 50000).Thesecondlinecontains n non-negativenumbersthatdonotexce...
PolycarpusadoresTVseries.Rightnowheisreadytofinishwatchingaseasonofapopularsitcom"GraphTheory".Intotal,theseasonhas n episodes,numberedwithintegersfrom 1 to n.Polycarpuswatchesepisodesnotonebyonebutinarandomorder.Hehasalreadywatchedalltheepisodesexceptforone.WhichepisodehasPolycaprusforgottentowatch?InputThefirstlineoftheinputcontainsinteger n (2 ≤ n ≤ 100000) —thenumbe...
DescriptionWearesupposedtomakeabudgetproposalforthismulti-sitecompetition.Thebudgetproposalisamatrixwheretherowsrepresentdifferentkindsofexpensesandthecolumnsrepresentdifferentsites.Wehadameetingaboutthis,sometimeagowherewediscussedthesumsoverdifferentkindsofexpensesandsumsoverdifferentsites.Therewasalsosometalkaboutspecialconstraints:someonementionedthatComputerCenterwouldneedatleast2000K...
Gensokyo isaworldwhichexistsquietlybesideours,separatedbyamysticalborder.Itisautopiawherehumansandotherbeingssuchasfairies, youkai(phantoms),andgodslivepeacefullytogether.ShameimaruAyaisacrowtenguwiththeabilitytomanipulatewindwhohasbeenin Gensokyo forover1000years.SherunstheBunbunmaruNews-anewspaperchock-fullofrumors,andownsthe Bunkachou -herrecordofinterestingobservationsforBunbun...
TheterroristgroupleadedbyawellknowninternationalterroristBenBladenisbulidinganuclearreactortoproduceplutoniumforthenuclearbombtheyareplanningtocreate.Beingthewickedcomputergeniusofthisgroup,youareresponsiblefordevelopingthecoolingsystemforthereactor.Thecoolingsystemofthereactorconsistsofthenumberofpipesthatspecialcoolingliquidflowsby.Pipesareconnectedatspecialpoints,callednodes,eachpipehasth...
Atthechildren'sday,thechildcametoPicks'shouse,andmessedhishouseup.Pickswasangryathim.Alotofimportantthingswerelost,inparticularthefavoritesetofPicks.Fortunately,Picksrememberssomethingabouthisset S:itselementsweredistinctintegersfrom 1 to limit;thevalueof wasequalto sum;here lowbit(x) equals 2k where k isthepositionofthefirstoneinthebinaryrepresentationof x.Forexample, low...
Onceuponatimeachildgotatestconsistingofmultiple-choicequestionsashomework.Amultiple-choicequestionconsistsoffourchoices: A, B, C and D.Eachchoicehasadescription,andthechildshouldfindouttheonlyonethatiscorrect.Fortunatelythechildknowshowtosolvesuchcomplicatedtest.Thechildwillfollowthealgorithm:Ifthereissomechoicewhosedescriptionatleasttwiceshorterthanallotherdescriptions,oratleasttwi...
Ofcourseourchildlikeswalkinginazoo.Thezoohas n areas,thatarenumberedfrom 1 to n.The i-thareacontains ai animalsinit.Alsothereare m roadsinthezoo,andeachroadconnectstwodistinctareas.Naturallythezooisconnected,soyoucanreachanyareaofthezoofromanyotherareausingtheroads.Ourchildisverysmart.Imaginethechildwanttogofromarea p toarea q.Firstlyheconsidersallthesimpleroutesfrom p to q...
OnChildren'sDay,thechildgotatoyfromDelayyyasapresent.However,thechildissonaughtythathecan'twaittodestroythetoy.Thetoyconsistsof n partsand m ropes.Eachropelinkstwoparts,buteverypairofpartsislinkedbyatmostonerope.Tosplitthetoy,thechildmustremoveallitsparts.Thechildcanremoveasinglepartatatime,andeachremoveconsumeanenergy.Let'sdefineanenergyvalueofpart i as vi.Thechildspend vf1 + ...
DescriptionGivenn,apositiveinteger,howmanypositiveintegerslessthannarerelativelyprimeton?Twointegersaandbarerelativelyprimeiftherearenointegersx>1,y>0,z>0suchthata=xyandb=xz.InputThereareseveraltestcases.Foreachtestcase,standardinputcontainsalinewithn<=1,000,000,000.Alinecontaining0followsthelastcase.OutputForeachtestcasethereshouldbesinglelineofoutputansweringthequestionposed...
近期评论