ACM算法讲解宣讲培训.ppt

  1. 1、本文档共82页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
ACM算法讲解宣讲培训.ppt

依次类推,经过n次比较和修正,在第(n-1)步,将求得vi到vj 的且中间顶点号不大于n-1的最短路径,这必是从vi到vj的最短路径。 图g中所有顶点偶对vi、vj间的最短路径长度对应一个n阶方阵D。在上述n+1步中,D的值不断变化,对应一个n阶方阵序列。 for(k=0;kn;++k){ for(i=0;in;++i){ for(j=0;jn;++j){ if(cost[i][j]cost[i][k]+cost[k][j]){ cost[i][j]=cost[i][k]+cost[k][j] } } } } Floyd-warshell 算法时间复杂度为O(n^3) 原程序实际上是这个DP的一个精巧的实现,省略了最后一维数组 练习题目 Toj 2870 The K-th City 单纯的Dijkstra Toj 2878 Internet is Faulty 先Floyed再Dijkstra, 而且路径权值是用乘法计算,可以直接把算法中的+变成*来解决,或者取对数,变成+计算亦可. Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound, 1 British pound buys 10.0 French francs, and 1 French franc buys 0.21 US dollar. Then, by converting currencies, a clever trader can start with 1 US dollar and buy 0.5 * 10.0 * 0.21 = 1.05 US dollars, making a profit of 5 percent. Your job is to write a program that takes a list of currency exchange rates as input and then determines whether arbitrage is possible or not. Input Specification The input file will contain one or more test cases. On the first line of each test case there is an integer n (1=n=30), representing the number of different currencies. The next n lines each contain the name of one currency. Within a name no spaces will appear. The next line contains one integer m, representing the length of the table to follow. The last m lines each contain the name ci of a source currency, a real number rij which represents the exchange rate from ci to cj and a name cj of the destination currency. Exchanges which do not appear in the table are impossible. Test cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for n. Output Specification For each test case, print one line telling whether arbitrage is possible or not in the format Case case: Yes respectively Case case: No Arbitrage(套利) 解题报告 Sample Input 3 USDollar BritishPound FrenchFranc 3 USD

文档评论(0)

youngyu0329 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档