文章标题 Arbitrage
来源:互联网 发布:自动抢购神器软件 编辑:程序博客网 时间:2024/06/18 04:12
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 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
题意:经过转化货币,某种货币会不会变多
#include<cstdio>#include<cstring>#include<iostream>using namespace std;struct node{ char s[100];}z[31];double map[32][32];int m;int judge(char b[]){ for(int i=1;i<=m;i++) { if(!strcmp(z[i].s,b)) return i; }}int Floyd(){ int i,j,k; for(k=1;k<=m;k++) for(i=1;i<=m;i++) for(j=1;j<=m;j++) map[i][j]=max(map[i][j],(map[i][k]*map[k][j])); for(i=1;i<=m;i++) { if(map[i][i]>1) return 1; } return 0;}int main(){ int t=0; while(~scanf("%d",&m)&&m) { int i,j; for(i=1;i<=m;i++) for(j=1;j<=m;j++) if(i==j) map[i][j]=1; else map[i][j]=0; for(i=1;i<=m;i++) scanf("%s",z[i].s); int n; char s1[100],s2[100]; double a; scanf("%d",&n); for(i=1;i<=n;i++) { getchar(); scanf("%s%lf%s",s1,&a,s2); int x=judge(s1); int y=judge(s2); map[x][y]=a; } int p=Floyd(); t++; if(p) printf("Case %d: Yes\n",t); else printf("Case %d: No\n",t); }}
- 文章标题 Arbitrage
- 文章标题 HDU 1217 : Arbitrage(最短路--Floyd+map)
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- Deep Learning(深度学习)学习笔记整理系列之(四)
- Centos6.5下用postgresql9.4.3源码安装
- Deep Learning(深度学习)学习笔记整理系列之(五)
- js 循环添加点击事件
- Installation failed with message INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries
- 文章标题 Arbitrage
- SpringMVC4 + Spring + MyBatis3 基于注解的最简配置
- python技巧小贴士一(1-8)
- 使用API帮助文档快速找到方法(中文版的)
- Protobuf3 系列一 第一个Java demo
- 确定集合中是否存在两个其和刚好为X的元素?
- 虚拟机上的linux系统连接外部网络
- tensorflow的基本用法(十)——保存神经网络参数和加载神经网络参数
- easyui重置表单以及clear和reset的区别