杭电 ACM HDU 1217 Arbitrage(最短路 floyd算法)

Arbitrage

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5272    Accepted Submission(s): 2418

Problem Description

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

The input file will contain one or more test cases. Om 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

For each test case, print one line telling whether arbitrage is possible or not in the format "Case case: Yes" respectively "Case case: No".

Sample Input

3
USDollar
BritishPound
FrenchFranc
3
USDollar 0.5 BritishPound
BritishPound 10.0 FrenchFranc
FrenchFranc 0.21 USDollar

3
USDollar
BritishPound
FrenchFranc
6
USDollar 0.5 BritishPound
USDollar 4.9 FrenchFranc
BritishPound 10.0 FrenchFranc
BritishPound 1.99 USDollar
FrenchFranc 0.09 BritishPound
FrenchFranc 0.19 USDollar

0

Sample Output

Case 1: Yes
Case 2: No

Source

University of Ulm Local Contest 1996

Recommend

Eddy   |   We have carefully selected several similar problems for you:  1142 2544 1874 1385 2066

时间: 2024-11-05 14:38:53

杭电 ACM HDU 1217 Arbitrage(最短路 floyd算法)的相关文章

[ACM] hdu 1217 Arbitrage (bellman_ford最短路,判断是否有正权回路或Floyed)

Arbitrage Problem Description 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 p

杭电ACM HDU 1869 六度分离

1967年,美国著名的社会学家斯坦利·米尔格兰姆提出了一个名为“小世界现象(small world phenomenon)”的著名假说,大意是说,任何2个素不相识的人中间最多只隔着6个人,即只用6个人就可以将他们联系在一起,因此他的理论也被称为 “六度分离”理论(six degrees of separation).虽然米尔格兰姆的理论屡屡应验,一直也有很多社会学家对其兴趣浓厚,但是在30多年的时间里,它从来就没有得到过严谨的证明,只 是一种带有传奇色彩的假说而已. Lele对这个理论相当有兴趣

[ACM] hdu 1217 Arbitrage (bellman_ford最短路,推断是否有正权回路或Floyed)

Arbitrage Problem Description 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 p

杭电ACM hdu 2079 选课时间 (模板)

Problem Description 又到了选课的时间了,xhd看着选课表发呆,为了想让下一学期好过点,他想知道学n个学分共有多少组合.你来帮帮他吧.(xhd认为一样学分的课没区别) Input输入数据的第一行是一个数据T,表示有T组数据.每组数据的第一行是两个整数n(1 <= n <= 40),k(1 <= k <= 8).接着有k行,每行有两个整数a(1 <= a <= 8),b(1 <= b <= 10),表示学分为a的课有b门. Output对于每

杭电ACM HDU 3790 最短路径问题

给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费,如果最短距离有多条路线,则输出花费最少的. Input 输入n,m,点的编号是1~n,然后是m行,每行4个数 a,b,d,p,表示a和b之间有一条边,且其长度为d,花费为p.最后一行是两个数 s,t;起点s,终点.n和m为0时输入结束. (1<n<=1000, 0<m<100000, s != t) Output 输出 一行有两个数, 最短距离及其花费. Sample Inpu

杭电 ACM HDU Train Problem I

Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 25008    Accepted Submission(s): 9435 Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays

杭电ACM hdu 1398 Square Coins

Problem Description People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ...

Arbitrage(最短路-floyd算法变形求正权)

Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16127   Accepted: 6780 Description 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 currenc

ACM: HDU 5418 Victor and World - Floyd算法+dp状态压缩

HDU 5418 Victor and World Time Limit:2000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u After trying hard for many years, Victor has finally received a pilot license. To have a celebration, he intends to buy himself an airplane and fl