(天梯赛)L2-001. 紧急救援

wang 发表于 图论 分类,标签: 天梯赛
作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图。在地图上显示有多个分散的城市和一些连接城市的快速道路。每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上。当其他城市有紧急求助电话给你的时候,你的任务是带领你的救援队尽快赶往事发地,同时,一路上召集尽可能多的救援队。输入格式:输入第一行给出4个正整数N、M、S、D,其中N(2<=N<=500)是城市的个数,顺便假设城市的编号为0~(N-1);M是快速道路的条数;S是出发地的城市编号;D是目的地的城市编号。第二行给出N个正整数,其中第i个数是第i个城市的救援队的数目,数字间以空格分隔。随后的M行中,每行给出一条快速道路的信息,分别是:城市1、城市2、快速道路的长度,中间用空格分开,数字均为整数且不超过500。输入保证救援可行且最优解唯一。输出格式:第一行输出不同的最短路径的条数和能够召集的最多的救援队数量...

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...