hdoj 1217 Arbitrage(floyd+处理名字为字符串的情况)
来源:互联网 发布:淘宝店铺音乐怎么修改 编辑:程序博客网 时间:2024/06/10 13:00
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 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.
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.
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
3USDollarBritishPoundFrenchFranc3USDollar 0.5 BritishPoundBritishPound 10.0 FrenchFrancFrenchFranc 0.21 USDollar3USDollarBritishPoundFrenchFranc6USDollar 0.5 BritishPoundUSDollar 4.9 FrenchFrancBritishPound 10.0 FrenchFrancBritishPound 1.99 USDollarFrenchFranc 0.09 BritishPoundFrenchFranc 0.19 USDollar0
Sample Output
Case 1: YesCase 2: No
Source
University of Ulm Local Contest 1996
这样写比map快很多!!!
#include"stdio.h"#include"string.h"struct node{ char name[33];}E[33];int main(){ double map[31][31]; double ans[31][31]; double t; char temp[33]; int k,n,m,k1,k2,i,j,Case=1; while(scanf("%d",&n),n) { for(i=1;i<=n;i++) scanf("%s",E[i].name); scanf("%d",&m); for(i=1;i<=n;i++) for(j=1;j<=n;j++) { if(i==j) map[i][j]=1; else map[i][j]=0; } for(i=1;i<=m;i++) { scanf("%s",temp); for(k1=1;k1<=n;k1++) if(strcmp(E[k1].name,temp)==0) break; scanf("%lf",&t); scanf("%s",temp); for(k2=1;k2<=n;k2++) if(strcmp(E[k2].name,temp)==0) break; map[k1][k2]=t; } for(i=1;i<=n;i++) { for(j=1;j<=n;j++) ans[i][j]=map[i][j]; } for(k=1;k<=n;k++) { for(i=1;i<=n;i++) { for(j=1;j<=n;j++) if(ans[i][j]<ans[i][k]*ans[k][j]) ans[i][j]=ans[i][k]*ans[k][j]; } } if(ans[1][1]>1) printf("Case %d: Yes\n",Case++); else printf("Case %d: No\n",Case++); } return 0;}
0 0
- hdoj 1217 Arbitrage(floyd+处理名字为字符串的情况)
- HDOJ 1217 Arbitrage (最短路 Floyd)
- HDOJ 1217 Arbitrage 【Floyd 有负权】
- HDOJ 题目1217 Arbitrage(最短路径,Floyd)
- HDOJ-1217Arbitrage(FLOYD最短路)
- hdoj 1217 Arbitrage 【最短路径】【floyd】
- hdu 1217 Arbitrage (Floyd)
- hdu 1217Arbitrage(Floyd)
- HDU 1217 Arbitrage(floyd)
- (Floyd)【HDU 1217】Arbitrage
- HDOJ 1217 Arbitrage(拟最短路,floyd算法)
- hdu 1217 Arbitrage (Floyd算法)
- HDU 1217 Arbitrage 货币交换(floyd)
- hdu 1217 Arbitrage (floyd+map)
- hdu 1217 Arbitrage (Floyd + 最大路径)
- POJ 2240 && HDU 1217 Arbitrage(Floyd)
- hdu 1217 Arbitrage (Floyd算法)
- HDU 1217 Arbitrage (floyd dp)
- 最近5年133个Java面试问题列表
- 应用jQuery插件pagination进行分页处理
- MSP430WARE++的使用4:GPIO的使用方法a
- virtualhost配置不成功,纠结了好几个小时的问题 :AH01630: client denied by server configuration
- hdu2665 主席树模板题
- hdoj 1217 Arbitrage(floyd+处理名字为字符串的情况)
- Linux查看磁盘剩余空间
- POJ 1828 解题报告
- java xml 框架 dom4j 解析 xml 字符串 和 利用 dom4j 创建 XML 的方法
- 数据可视化 -- 入门(draft version)
- Linux下如何卸载软件(Debian系)
- 【NYOJ】[8]一种排序
- JavaScript继承详解(一)
- 【吐槽】这是第200篇博文