Arbitrage

Time Limit: 1000MS

Memory Limit: 65536K

Total Submissions: 10954

Accepted: 4608

题目链接:http://poj.org/problem?id=2240

Description

Arbitrage is the use of discrepancies in currencyexchange rates to transform one unit of a currency into more than one unit ofthe same currency. For example, suppose that 1 US Dollar buys 0.5 Britishpound, 1 British pound buys 10.0 French francs, and 1 French franc buys 0.21 USdollar. Then, by converting currencies, a clever trader can start with 1 USdollar and buy 0.5 * 10.0 * 0.21 = 1.05 US dollars, making a profit of 5percent.

Your job is to write a program that takes a list of currency exchange rates asinput and then determines whether arbitrage is possible or not.

Input

The input will contain one or more test cases. Om thefirst line of each test case there is an integer n (1<=n<=30),representing the number of different currencies. The next n lines each containthe name of one currency. Within a name no spaces will appear. The next linecontains one integer m, representing the length of the table to follow. Thelast m lines each contain the name ci of a source currency, a real number rijwhich represents the exchange rate from ci to cj and a name cj of thedestination currency. Exchanges which do not appear in the table areimpossible.
Test cases are separated from each other by a blank line. Input is terminatedby a value of zero (0) for n.

Output

For each test case, print one line telling whetherarbitrage 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

Ulm Local 1996

题意:

就是将货币兑换,问这样兑换能否盈利

解题思路:

根据题意给出的字符串建立图,在用flody算法计算任意两个点之间的距离,用乘号不用加号,最后变量一遍图中(i,i)节点,如果有存在大于1的就输出Yes,否则输出No。

代码:

#include <iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define MAX 40
#define VALUE 0xffffff
using namespace std;
struct word
{int id;char wd[50];
};
word w[MAX];
double g[MAX][MAX];
int n;void flody()
{for(int k=1;k<=n;k++){for(int j=1;j<=n;j++){for(int i=1;i<=n;i++){if(g[i][j]<g[i][k]*g[k][j]){g[i][j]=g[i][k]*g[k][j];}}}}
}int getId(char *wd)
{for(int i=1;i<=n;i++){if(strcmp(wd,w[i].wd)==0)return w[i].id;}return 0;
}int main()
{int i;char a[MAX],b[MAX];float rate;int flag=1;while(true){memset(g,0,sizeof(g));scanf("%d",&n);if(n==0)break;getchar();for(i=1;i<=n;i++){gets(w[i].wd);w[i].id=i;}int count;scanf("%d",&count);while(count--){getchar();cin>>a>>rate>>b;int id1=getId(a);int id2=getId(b);g[id1][id2]=rate;}flody();for(i=1;i<=n;i++){if(g[i][i]>1){printf("Case %d: Yes\n",flag);break;}}if(i==(n+1)){printf("Case %d: No\n",flag);}flag++;}return 0;
}

poj_2240 Arbitrage相关推荐

  1. I - Arbitrage POJ - 2240

    I - Arbitrage POJ - 2240 题意: 利用汇率之间的差价判断是否可以赚钱 思路: 利用 spfa 跑最长路(即松弛条件改为取更大的值),判断是否存在正环,存在则可以赚钱 #incl ...

  2. Arbitrage——判断正环Bellman-Ford/SPFA

    [题目描述] Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a c ...

  3. HDU 1217 Arbitrage (Floyd + SPFA判环)

    题目链接:HDU 1217 Arbitrage 简单的货币转换问题,给定多种货币,以及货币之间的汇率,问能否通过货币的转换实现收益. 例如: 1 US Dollar buys 0.5 British ...

  4. Arbitrage(判断正环 spfa写法)

    题目如下: Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a cu ...

  5. POJ 2240 Arbitrage(SPFA判正环)

    POJ 2240 Arbitrage 题目大意 套利是指利用货币汇率的差异,将一种货币的一个单位转换为同一货币的多个单位.例如,假设1美元买0.5英镑,1英镑买10.0法国法郎,1法国法郎买0.21美 ...

  6. I - Arbitrage(判断是否有无正环 II)

    题目描述 Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a cur ...

  7. HDOJ 题目1217 Arbitrage(最短路径,Floyd)

    NEW~ 关于举办计算机学院大学生程序设计竞赛(2014'11)的报名通知 Arbitrage Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  8. 统计套利 Statistical arbitrage

    统计套利  Statistical arbitrage 不是绝对意义上的套利, 而是统计意义上的套利,即该策略期望上可套利,但不 一定能套利. From Wikipedia, the free enc ...

  9. Arbitrage题解

    START emmmm,做法和其他几个题解应该差不多,但是我觉得解释可以再多一点. 那么废话不多说. 这道题的要求比较简单,只是要求最后转换成原来的那种货币时获利大于0.01(1%),而且转换次数不超 ...

最新文章

  1. Strategy_Requirement2
  2. 优秀学生是如何高效利用时间的?
  3. Ubuntu 12.04 Server 搭建DNS服务器
  4. 前端开发工具 vscode 使用技巧篇:控制台由powershell切换为cmd方法,windows下新旧版控制台cmd与powershell互切方法
  5. 为什么使用HashMap需要重写hashcode和equals方法_为什么要重写hashcode和equals方法?你能说清楚了吗...
  6. 为什么人们默认 x86 代表 32 位处理器
  7. hive集群部署以及beeline和hive
  8. OpenCV里IplImage的widthStep参数 和width参数
  9. windows7正版验证_Windows7 寿终正寝:那些一并消逝的软件你知多少?
  10. eclipse各个版本的区别
  11. Linux内存管理:Fixmaps(固定映射地址)和ioremap
  12. PubMedQA生物医学研究问题解答数据集(2019)下载
  13. 戴尔服务器怎么远程安装系统,DELL-远程安装系统操作手册
  14. Apache日志格式与配置
  15. buu刷题日记 asis2016_b00ks
  16. Alex(ALEXANDER的简写,.亚历山大)
  17. C++相关问题笔记(一)
  18. 区块链的未来:“2020年起3-5年:国内区块链大规模商业应用将全面落地开花”
  19. 数学中的术语与常用表达
  20. av_interleaved_write_frame(fmt_ctx, enc_pkt);返回-22

热门文章

  1. 【开源推介02-pyang】-你离yang模型只差一个pyang工具
  2. iPhone6 AirDrop找不到我的mac解决方法!注销mac和iPhone的icloud账号
  3. 模型训练的性能优化方法
  4. Aspects swift 源代码分析
  5. 中国教育之------------------记录中华美德-(持续更新)
  6. Linux使用nexus搭建maven私服
  7. 苹果也是纸老虎,其nano-sim标准真是另人精艳
  8. 修马达的php源码,查看SKU:RB-02S087 振动马达模块的源代码
  9. k8s 创建job 执行oc命令 删除/操作宿主机内pod
  10. 计算机二级Office应用之Excel中的函数(1)