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...
DescriptionTheFareySequenceFnforanyintegernwithn>=2isthesetofirreduciblerationalnumbersa/bwith0<a<b<=nandgcd(a,b)=1arrangedinincreasingorder.ThefirstfewareF2={1/2}F3={1/3,1/2,2/3}F4={1/4,1/3,1/2,2/3,3/4}F5={1/5,1/4,1/3,2/5,1/2,3/5,2/3,3/4,4/5}YoutaskistocalculatethenumberoftermsintheFareysequenceFn.InputThereareseveraltestcases.Eachtestcasehasonlyoneline,whichcontainsap...
近期评论