Asyouknow,anundirectedconnectedgraphwithnnodesandn - 1edgesiscalledatree.Youaregivenanintegerdandatreeconsistingofnnodes.Eachnodeihasavalueaiassociatedwithit.WecallasetSoftreenodesvalidiffollowingconditionsaresatisfied:Sisnon-empty.Sisconnected.Inotherwords,ifnodesuandvareinS,thenallnodeslyingonthesimplepathbetweenuandvshouldalsobepresentedinS..Yourtaskistocountthenumberofvalidsets.S...
Namisplayingwithastringonhiscomputer.ThestringconsistsofnlowercaseEnglishletters.Itismeaningless,soNamdecidedtomakethestringmorebeautiful,thatistomakeitbeapalindromebyusing4arrowkeys:left,right,up,down.Thereisacursorpointingatsomesymbolofthestring.Supposethatcursorisatpositioni(1 ≤ i ≤ n,thestringuses1-basedindexing)now.Leftandrightarrowkeysareusedtomovecursoraroundthestring.Thestri...
Let'sdefinelogicalORasanoperationontwologicalvalues(i.e.valuesthatbelongtotheset{0, 1})thatisequalto1ifeitherorbothofthelogicalvaluesissetto1,otherwiseitis0.WecandefinelogicalORofthreeormorelogicalvaluesinthesamemanner:whereisequalto1ifsomeai = 1,otherwiseitisequalto0.NamhasamatrixAconsistingofmrowsandncolumns.Therowsarenumberedfrom1tom,columnsarenumberedfrom1ton.Elementatrowi(1 ≤ ...
Forapositiveintegernlet'sdefineafunctionf:f(n) = - 1 + 2 - 3 + .. + ( - 1)nnYourtaskistocalculatef(n)foragivenintegern.InputThesinglelinecontainsthepositiveintegern(1 ≤ n ≤ 1015).OutputPrintf(n)inasingleline.Sampletest(s)input[crayon-684abfbc1d9b1332961472/]output[crayon-684abfbc1d9b9257998996/]input[crayon-684abfbc1d9bc230665342/]output[crayon-684abfbc1d9bf323647740/]N...
近期评论