AndrewandEugeneareplayingagame.Initially,Andrewhasstrings,consistingofdigits.EugenesendsAndrewmultiplequeriesoftype"di → ti",thatmeans"replacealldigitsdiinstringswithsubstringsequaltoti".Forexample,ifs = 123123,thenquery"2 → 00"transformssto10031003,andquery"3 → "("replace3byanemptystring")transformsittos = 1212.AfterallthequeriesEugeneasksAndrewtofindtheremainderafterdivisi...
Peterhadacubewithnon-zerolengthofaside.Heputthecubeintothree-dimensionalspaceinsuchawaythatitsverticeslayatintegerpoints(itispossiblethatthecube'ssidesarenotparalleltothecoordinateaxes).Thenhetookapieceofpaperandwrotedowneightlines,eachcontainingthreeintegers—coordinatesofcube'svertex(asinglelinecontainscoordinatesofasinglevertex,eachvertexiswrittenexactlyonce),putthepaperonthetableandleft.Wh...
Paulhatespalindromes.HeassumesthatstringsistolerableifeachitscharacterisoneofthefirstplettersoftheEnglishalphabetandsdoesn'tcontainanypalindromecontiguoussubstringoflength2ormore.Paulhasfoundatolerablestringsoflengthn.Helphimfindthelexicographicallynexttolerablestringofthesamelengthorelsestatethatsuchstringdoesnotexist.InputThefirstlinecontainstwospace-separatedintegers:nandp(1 ≤ n ≤ ...
Description Duetoalackofrain,FarmerJohnwantstobuildanirrigationsystemtosendwaterbetweenhisNfields(1<=N<=2000).Eachfieldiisdescribedbyadistinctpoint(xi,yi)inthe2Dplane,with0<=xi,yi<=1000.ThecostofbuildingawaterpipebetweentwofieldsiandjisequaltothesquaredEuclideandistancebetweenthem:(xi-xj)^2+(yi-yj)^2FJwouldliketobuildaminimum-costsystemofpipessothatallofhisfieldsarelinkedt...
DescriptionFarmerJohngoestoDollarDaysatTheCowStoreanddiscoversanunlimitednumberoftoolsonsale.Duringhisfirstvisit,thetoolsaresellingvariouslyfor$1,$2,and$3.FarmerJohnhasexactly$5tospend.Hecanbuy5toolsat$1eachor1toolat$3andanadditional1toolat$2.Ofcourse,thereareothercombinationsforatotalof5differentwaysFJcanspendallhismoneyontools.Heretheyare:1@US$3+1@US$21@US$3+2@US$11@US$...
近期评论