DescriptionInthisproblem,youhavetoanalyzeaparticularsortingalgorithm.Thealgorithmprocessesasequenceofndistinctintegersbyswappingtwoadjacentsequenceelementsuntilthesequenceissortedinascendingorder.Fortheinputsequence91054,Ultra-QuickSortproducestheoutput01459.YourtaskistodeterminehowmanyswapoperationsUltra-QuickSortneedstoperforminordertosortagiveninputsequence.InputTheinputcontainssev...
InnaandDimadecidedtosurpriseSereja.Theybroughtareallyhugecandymatrix,it'sbigevenforSereja!Let'snumbertherowsofthegiantmatrixfrom 1 to n fromtoptobottomandthecolumns—from 1 to m,fromlefttoright.We'llrepresentthecellontheintersectionofthe i-throwand j-thcolumnas (i, j).Justasisexpected,somecellsofthegiantcandymatrixcontaincandies.Overallthematrixhas p candies:the k-thcandyisa...
Innalikessweetsandagamecalledthe"CandyMatrix".Today,shecameupwiththenewgame"CandyMatrix2:Reload".Thefieldforthenewgameisarectangletableofsize n × m.Eachlineofthetablecontainsonecellwithadwarffigurine,onecellwithacandy,theothercellsofthelineareempty.Thegamelastsforseveralmoves.Duringeachmovetheplayercanchoose alllinesofthematrixwheredwarfisnotonthecellwithcandy andshout"Let'sgo!"....
Therealwaysissomethingtochoosefrom!Andnow,insteadof"NoughtsandCrosses",Innachooseaveryunusualupgradeofthisgame.Therulesofthegamearegivenbelow:Thereisonepersonplayingthegame.Beforethebeginningofthegameheputs12cardsinarowonthetable.Eachcardcontainsacharacter:"X"or"O".Thentheplayerchoosestwopositiveintegers a and b (a·b = 12),afterthathemakesatableofsize a × b fromthecardshepu...
近期评论