最短路径算法.docx

上传人:b****4 文档编号:3698831 上传时间:2022-11-24 格式:DOCX 页数:9 大小:23.16KB
下载 相关 举报
最短路径算法.docx_第1页
第1页 / 共9页
最短路径算法.docx_第2页
第2页 / 共9页
最短路径算法.docx_第3页
第3页 / 共9页
最短路径算法.docx_第4页
第4页 / 共9页
最短路径算法.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

最短路径算法.docx

《最短路径算法.docx》由会员分享,可在线阅读,更多相关《最短路径算法.docx(9页珍藏版)》请在冰豆网上搜索。

最短路径算法.docx

最短路径算法

1860:

CurrencyExchange

TimeLimit:

1000MS

MemoryLimit:

30000K

TotalSubmissions:

12943

Accepted:

4415

Description

Severalcurrencyexchangepointsareworkinginourcity.Letussupposethateachpointspecializesintwoparticularcurrenciesandperformsexchangeoperationsonlywiththesecurrencies.Therecanbeseveralpointsspecializinginthesamepairofcurrencies.Eachpointhasitsownexchangerates,exchangerateofAtoBisthequantityofByougetfor1A.Alsoeachexchangepointhassomecommission,thesumyouhavetopayforyourexchangeoperation.Commissionisalwayscollectedinsourcecurrency.

Forexample,ifyouwanttoexchange100USDollarsintoRussianRublesattheexchangepoint,wheretheexchangerateis29.75,andthecommissionis0.39youwillget(100-0.39)*29.75=2963.3975RUR.

YousurelyknowthatthereareNdifferentcurrenciesyoucandealwithinourcity.Letusassignuniqueintegernumberfrom1toNtoeachcurrency.Theneachexchangepointcanbedescribedwith6numbers:

integerAandB-numbersofcurrenciesitexchanges,andrealRAB,CAB,RBAandCBA-exchangeratesandcommissionswhenexchangingAtoBandBtoArespectively.

NickhassomemoneyincurrencySandwondersifhecansomehow,aftersomeexchangeoperations,increasehiscapital.Ofcourse,hewantstohavehismoneyincurrencySintheend.Helphimtoanswerthisdifficultquestion.Nickmustalwayshavenon-negativesumofmoneywhilemakinghisoperations.

Input

Thefirstlineoftheinputcontainsfournumbers:

N-thenumberofcurrencies,M-thenumberofexchangepoints,S-thenumberofcurrencyNickhasandV-thequantityofcurrencyunitshehas.ThefollowingMlinescontain6numberseach-thedescriptionofthecorrespondingexchangepoint-inspecifiedaboveorder.Numbersareseparatedbyoneormorespaces.1<=S<=N<=100,1<=M<=100,Visrealnumber,0<=V<=103.

Foreachpointexchangeratesandcommissionsarereal,givenwithatmosttwodigitsafterthedecimalpoint,10-2<=rate<=102,0<=commission<=102.

Letuscallsomesequenceoftheexchangeoperationssimpleifnoexchangepointisusedmorethanonceinthissequence.Youmayassumethatratioofthenumericvaluesofthesumsattheendandatthebeginningofanysimplesequenceoftheexchangeoperationswillbelessthan104.

Output

IfNickcanincreasehiswealth,outputYES,inothercaseoutputNOtotheoutputfile.

SampleInput

32120.0

121.001.001.001.00

231.101.001.101.00

SampleOutput

YES

Source

NortheasternEurope2001,NorthernSubregion

Language:

3259:

Wormholes

TimeLimit:

2000MS

MemoryLimit:

65536K

TotalSubmissions:

19546

Accepted:

6879

Description

Whileexploringhismanyfarms,FarmerJohnhasdiscoveredanumberofamazingwormholes.Awormholeisverypeculiarbecauseitisaone-waypaththatdeliversyoutoitsdestinationatatimethatisBEFOREyouenteredthewormhole!

EachofFJ'sfarmscomprisesN(1≤N≤500)fieldsconvenientlynumbered1..N,M(1≤M≤2500)paths,andW(1≤W≤200)wormholes.

AsFJisanavidtime-travelingfan,hewantstodothefollowing:

startatsomefield,travelthroughsomepathsandwormholes,andreturntothestartingfieldatimebeforehisinitialdeparture.Perhapshewillbeabletomeethimself:

).

TohelpFJfindoutwhetherthisispossibleornot,hewillsupplyyouwithcompletemapstoF(1≤F≤5)ofhisfarms.Nopathswilltakelongerthan10,000secondstotravelandnowormholecanbringFJbackintimebymorethan10,000seconds.

Input

Line1:

Asingleinteger,F.Ffarmdescriptionsfollow.

Line1ofeachfarm:

Threespace-separatedintegersrespectively:

N,M,andW

Lines2..M+1ofeachfarm:

Threespace-separatednumbers(S,E,T)thatdescribe,respectively:

abidirectionalpathbetweenSandEthatrequiresTsecondstotraverse.Twofieldsmightbeconnectedbymorethanonepath.

LinesM+2..M+W+1ofeachfarm:

Threespace-separatednumbers(S,E,T)thatdescribe,respectively:

AonewaypathfromStoEthatalsomovesthetravelerbackTseconds.

Output

Lines1..F:

Foreachfarm,output"YES"ifFJcanachievehisgoal,otherwiseoutput"NO"(donotincludethequotes).

SampleInput

2

331

122

134

231

313

321

123

234

318

SampleOutput

NO

YES

Hint

Forfarm1,FJcannottravelbackintime.

Forfarm2,FJcouldtravelbackintimebythecycle1->2->3->1,arrivingbackathisstartinglocation1secondbeforeheleaves.Hecouldstartfromanywhereonthecycletoaccomplishthis.

Source

USACO2006DecemberGold

1062:

昂贵的聘礼

TimeLimit:

1000MS

MemoryLimit:

10000K

TotalSubmissions:

26529

Accepted:

7391

Description

年轻的探险家来到了一个印第安部落里。

在那里他和酋长的女儿相爱了,于是便向酋长去求亲。

酋长要他用10000个金币作为聘礼才答应把女儿嫁给他。

探险家拿不出这么多金币,便请求酋长降低要求。

酋长说:

"嗯,如果你能够替我弄到大祭司的皮袄,我可以只要8000金币。

如果你能够弄来他的水晶球,那么只要5000金币就行了。

"探险家就跑到大祭司那里,向他要求皮袄或水晶球,大祭司要他用金币来换,或者替他弄来其他的东西,他可以降低价格。

探险家于是又跑到其他地方,其他人也提出了类似的要求,或者直接用金币换,或者找到其他东西就可以降低价格。

不过探险家没必要用多样东西去换一样东西,因为不会得到更低的价格。

探险家现在很需要你的帮忙,让他用最少的金币娶到自己的心上人。

另外他要告诉你的是,在这个部落里,等级观念十分森严。

地位差距超过一定限制的两个人之间不会进行任何形式的直接接触,包括交易。

他是一个外来人,所以可以不受这些限制。

但是如果他和某个地位较低的人进行了交易,地位较高的的人不会再和他交易,他们认为这样等于是间接接触,反过来也一样。

因此你需要在考虑所有的情况以后给他提供一个最好的方案。

为了方便起见,我们把所有的物品从1开始进行编号,酋长的允诺也看作一个物品,并且编号总是1。

每个物品都有对应的价格P,主人的地位等级L,以及一系列的替代品Ti和该替代品所对应的"优惠"Vi。

如果两人地位等级差距超过了M,就不能"间接交易"。

你必须根据这些数据来计算出探险家最少需要多少金币才能娶到酋长的女儿。

Input

输入第一行是两个整数M,N(1<=N<=100),依次表示地位等级差距限制和物品的总数。

接下来按照编号从小到大依次给出了N个物品的描述。

每个物品的描述开头是三个非负整数P、L、X(X

接下来X行每行包括两个整数T和V,分别表示替代品的编号和"优惠价格"。

Output

输出最少需要的金币数。

SampleInput

14

1000032

28000

35000

100021

4200

300021

4200

5020

SampleOutput

5250

Source

浙江

2253:

Frogger

TimeLimit:

1000MS

MemoryLimit:

65536K

TotalSubmissions:

17010

Accepted:

5556

Description

FreddyFrogissittingonastoneinthemiddleofalake.SuddenlyhenoticesFionaFrogwhoissittingonanotherstone.Heplanstovisither,butsincethewaterisdirtyandfulloftourists'sunscreen,hewantstoavoidswimmingandinsteadreachherbyjumping.

UnfortunatelyFiona'sstoneisoutofhisjumprange.ThereforeFreddyconsiderstouseotherstonesasintermediatestopsandreachherbyasequenceofseveralsmalljumps.

Toexecuteagivensequenceofjumps,afrog'sjumprangeobviouslymustbeatleastaslongasthelongestjumpoccuringinthesequence.

Thefrogdistance(humansalsocallitminimaxdistance)betweentwostonesthereforeisdefinedastheminimumnecessaryjumprangeoverallpossiblepathsbetweenthetwostones.

YouaregiventhecoordinatesofFreddy'sstone,Fiona'sstoneandallotherstonesinthelake.YourjobistocomputethefrogdistancebetweenFreddy'sandFiona'sstone.

Input

Theinputwillcontainoneormoretestcases.Thefirstlineofeachtestcasewillcontainthenumberofstonesn(2<=n<=200).Thenextnlineseachcontaintwointegersxi,yi(0<=xi,yi<=1000)representingthecoordinatesofstone#i.Stone#1isFreddy'sstone,stone#2isFiona'sstone,theothern-2stonesareunoccupied.There'sablanklinefollowingeachtestcase.Inputisterminatedbyavalueofzero(0)forn.

Output

Foreachtestcase,printalinesaying"Scenario#x"andalinesaying"FrogDistance=y"wherexisreplacedbythetestcasenumber(theyarenumberedfrom1)andyisreplacedbytheappropriaterealnumber,printedtothreedecimals.Putablanklineaftereachtestcase,evenafterthelastone.

SampleInput

2

00

34

3

174

194

185

0

SampleOutput

Scenario#1

FrogDistance=5.000

Scenario#2

FrogDistance=1.414

Source

UlmLocal1997

1125StockbrokerGrapevine

TimeLimit:

1000MS

MemoryLimit:

10000K

TotalSubmissions:

20488

Accepted:

11109

Description

Stockbrokersareknowntooverreacttorumours.Youhavebeencontractedtodevelopamethodofspreadingdisinformationamongstthestockbrokerstogiveyouremployerthetacticaledgeinthestockmarket.Formaximumeffect,youhavetospreadtherumoursinthefastestpossibleway.

Unfortunatelyforyou,stockbrokersonlytrustinformationcomingfromtheir"Trustedsources"Thismeansyouhavetotakeintoaccountthestructureoftheircontactswhenstartingarumour.Ittakesacertainamountoftimeforaspecificstockbrokertopasstherumourontoeachofhiscolleagues.Yourtaskwillbetowriteaprogramthattellsyouwhichstockbrokertochooseasyourstartingpointfortherumour,aswellasthetimeitwilltakefortherumourtospreadthroughoutthestockbrokercommunity.Thisdurationismeasuredasthetimeneededforthelastpersontoreceivetheinformation.

Input

Yourprogramwillinputdatafordifferentsetsofstockbrokers.Eachsetstartswithalinewiththenumberofstockbrokers.Followingthisisalineforeachstockbrokerwhichcontainsthenumberofpeoplewhotheyhavecontactwith,whothesepeopleare,andthetimetakenforthemtopassthemessagetoeachperson.Theformatofeachstockbrokerlineisasfollows:

Thelinestartswiththenumberofcontacts(n),followedbynpairsofintegers,onepairforeachcontact.Eachpairlistsfirstanumberreferringtothecontact(e.g.a'1'meanspersonnumberoneintheset),followedbythetimeinminutestakentopassamessagetothatperson.Therearenospecialpunctuationsymbolsorspacingrules.

Eachpersonisnumbered1throughtothenumberofstockbrokers.Thetimetakentopassthemessageonwillbebetween1and10minutes(inclusive),andthenumberofcontactswillrangebetween0andonelessthanthenumberofstockbrokers.Thenumberofstockbrokerswillrangefrom1to100.Theinputisterminatedbyasetofstockbrokerscontaining0(zero)people.

Output

Foreachsetofdata,yourprogrammustoutputasinglelinecon

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1