2017pat甲级题目1125. Chain the Ropes (25)

发表于 动态规划 分类,标签: pat
 Givensomesegmentsofrope,youaresupposedtochainthemintoonerope.Eachtimeyoumayonlyfoldtwosegmentsintoloopsandchainthemintoonepiece,asshownbythefigure.Theresultingchainwillbetreatedasanothersegmentofropeandcanbefoldedagain.Aftereachchaining,thelengthsoftheoriginaltwosegmentswillbehalved.Yourjobistomakethelongestpossibleropeo...

2017pat甲级题目1124. Raffle for Weibo Followers (20)

发表于 模拟 分类,标签: pat
 JohngotafullmarkonPAT.Hewassohappythathedecidedtoholdaraffle(抽奖)forhisfollowersonWeibo--thatis,hewouldselectwinnersfromeveryNfollowerswhoforwardedhispost,andgiveawaygifts.Nowyouaresupposedtohelphimgeneratethelistofwinners.InputSpecification:Eachinputfilecontainsonetestcase.Foreachcase,thefirstlinegivesthreepositiveintegers...

PAT (Advanced Level)1122. Hamiltonian Cycle (25)

发表于 图论 分类,标签: pat
  The"Hamiltoncycleproblem"istofindasimplecyclethatcontainseveryvertexinagraph.Suchacycleiscalleda"Hamiltoniancycle".Inthisproblem,youaresupposedtotellifagivencycleisaHamiltoniancycle.InputSpecification:Eachinputfilecontainsonetestcase.Foreachcase,thefirstlinecontains2positiveintegersN(2<N<=200),then...

PAT (Advanced Level)1121. Damn Single (25)

发表于 模拟 分类,标签: pat
 "DamnSingle(单身狗)"istheChinesenicknameforsomeonewhoisbeingsingle.Youaresupposedtofindthosewhoarealoneinabigparty,sotheycanbetakencareof.InputSpecification:Eachinputfilecontainsonetestcase.Foreachcase,thefirstlinegivesapositiveintegerN(<=50000),thetotalnumberofcouples.ThenNlinesofthecouplesfollow,eachgivesacoupleo...

PAT (Advanced Level)1120. Friend Numbers (20)

发表于 模拟 分类,标签: pat
 Twointegersarecalled"friendnumbers"iftheysharethesamesumoftheirdigits,andthesumistheir"friendID".Forexample,123and51arefriendnumberssince1+2+3=5+1=6,and6istheirfriendID.Givensomenumbers,youaresupposedtocountthenumberofdifferentfriendID'samongthem.Note:anumberisconsideredafriendofitself.InputSpecificati...

PAT (Advanced Level)1118. Birds in Forest (25)

发表于 并查集 分类,标签: pat
 Somescientiststookpicturesofthousandsofbirdsinaforest.Assumethatallthebirdsappearinthesamepicturebelongtothesametree.Youaresupposedtohelpthescientiststocountthemaximumnumberoftreesintheforest,andforanypairofbirds,telliftheyareonthesametree.InputSpecification:Eachinputfilecontainsonetestcase.Foreachcase,thefirstlinecontains...

PAT (Advanced Level)1117. Eddington Number(25)

发表于 模拟 分类,标签: pat
 BritishastronomerEddingtonlikedtorideabike.Itissaidthatinordertoshowoffhisskill,hehasevendefinedan"Eddingtonnumber",E--thatis,themaximumintegerEsuchthatitisforEdaysthatoneridesmorethanEmiles.Eddington'sownEwas87.Nowgiveneveryday'sdistancesthatoneridesforNdays,youaresupposedtofindthecorrespondingE(<=N)....

PAT (Advanced Level)1116. Come on! Let's C (20)

发表于 模拟 分类,标签: pat
 "Let'sC"isapopularandfunprogrammingcontesthostedbytheCollegeofComputerScienceandTechnology,ZhejiangUniversity.Sincetheideaofthecontestisforfun,theawardrulesarefunnyasthefollowing:0.TheChampionwillreceivea"MysteryAward"(suchasaBIGcollectionofstudents'researchpapers...).1.Thosewhorankedasaprimenumberwillre...

PAT (Advanced Level)1115. Counting Nodes in a BST (30)

发表于 分类,标签: pat二叉树
 ABinarySearchTree(BST)isrecursivelydefinedasabinarytreewhichhasthefollowingproperties:Theleftsubtreeofanodecontainsonlynodeswithkeyslessthanorequaltothenode'skey.Therightsubtreeofanodecontainsonlynodeswithkeysgreaterthanthenode'skey.Boththeleftandrightsubtreesmustalsobebinarysearchtrees.Insertasequenceofnumbersintoani...

PAT (Advanced Level)1114. Family Property (25)

发表于 并查集 分类,标签: pat
 Thistime,youaresupposedtohelpuscollectthedataforfamily-ownedproperty.Giveneachperson'sfamilymembers,andtheestate(房产)infounderhis/herownname,weneedtoknowthesizeofeachfamily,andtheaverageareaandnumberofsetsoftheirrealestate.InputSpecification:Eachinputfilecontainsonetestcase.Foreachcase,thefirstlinegivesapositiveintegerN(<...