题意  给你n种币种之间的汇率关系  推断是否能形成套汇现象  即某币种多次换为其他币种再换回来结果比原来多

基础的最短路  仅仅是加号换为了乘号

#include<cstdio>
#include<cstring>
#include<string>
#include<map>
using namespace std;
map<string, int> na;
const int N = 31;
double d[N], rate[N][N], r;
int n, m, ans;int bellman(int s)
{memset(d, 0, sizeof(d));d[s] = 1.0;for(int k = 1; k <= n; ++k){for(int i = 1; i <= n; ++i){for(int j = 1; j <= n; ++j)if(d[i] < d[j]*rate[j][i])d[i] = d[j] * rate[j][i];}}return d[s] > 1.0;
}int main()
{int cas = 0;char s[100], a[100], b[100];while(scanf("%d", &n), n){na.clear();ans = 0;memset(rate, 0, sizeof(rate));for(int i = 1; i <= n; ++i){rate[i][i] = 1.0;scanf("%s", s);na[s] = i;}scanf("%d", &m);for(int i = 1; i <= m; ++i){scanf("%s%lf%s", a, &r, b);rate[na[a]][na[b]] = r;}for(int i = 1; i <= n; ++i){if(bellman(i)){ans = 1; break;}}printf("Case %d: %s\n", ++cas, ans ? "Yes" : "No");}return 0;
}
Arbitrage

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 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 USDollar3
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 USDollar0

Sample Output

Case 1: Yes
Case 2: No

POJ 2240 Arbitrage(最短路 套汇)相关推荐

  1. POJ 2240 Arbitrage(SPFA判正环)

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

  2. poj 2240 Arbitrage (Floyd)

    链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...

  3. poj 2240 Arbitrage (floyd 变形)

    http://poj.org/problem?id=2240 floyd 的变形 题意 有n个货币,他们的交换情况m个 例如: 3 USDollar BritishPound FrenchFranc ...

  4. POJ 2240 Arbitrage(判正环)

    http://poj.org/problem?id=2240 题意: 货币兑换,判断最否是否能获利. 思路: 又是货币兑换题,Belloman-ford和floyd算法都可以的. 1 #include ...

  5. poj 2240 Arbitrage(bellman-ford spfa 判断正环)

    http://poj.org/problem?id=2240 基本和poj 1860相同 只是把单点变成了任意点 做完1860再做这题就完全把思路套上就过了 做完才发现网上的题解都用的是floyd 不 ...

  6. POJ 2240 Arbitrage

    这一题是一道比较好的最短路的变型题,大致思路是求得本身到本身的最短路,注意这一题路与路是相乘的关系,用floy的算法即可. AC code: View Code 1 #include <iost ...

  7. POJ 2240 Arbitrage Bellman_ford 判读是否存在正环

    和POJ1860差不多,就是用bellmanford判读是否存在正环,注意的是同种货币之间也可以交换,就是说:A货币换A货币汇率是2的情况也是存在的. #include<stdio.h> ...

  8. POJ 2240 Arbitrage 解题报告

    Question Link 单向图,就是bellman-ford求正环,但是应该预设起点的钱的值为1,或者任意正数.起点暴力,枚举.好吧(其实我是真的傻了). 傻傻的代码 #include<io ...

  9. I - Arbitrage POJ - 2240

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

最新文章

  1. 高德地图小蓝点_一会晴天一会下雨?夏日想要顺利出行 高德地图这些小功能最实用...
  2. Effective_STL 学习笔记(四十三) 尽量用算法调用代替手写循环
  3. POJ 1651 Multiplication Puzzle 区间dp(水
  4. [渝粤教育] 西南科技大学 建筑制图 在线考试复习资料(1)
  5. 如何搭建socks5和ss节点_redis cluster搭建实践(非常详细,值得收藏)
  6. 阿里云发布时间序列数据库TSDB,关于时序你了解多少?
  7. vsftpd 源码安装 linux/redhat
  8. 创宇技能表_知道创宇研发技能表 一
  9. web大前端开发中一些常见的安全性问题
  10. 酒店管理系统-概要设计说明书
  11. 离线网页 HTML+CSS+DIV
  12. 22种大数据分析可视化工具
  13. 主线剧情0.0-Linux学习资源大综合
  14. 华为去年AI研发投入15亿美元,人才年薪平均30万美元
  15. 论文翻译 WiscKey: Separating Keys from Values in SSD-Conscious Storage
  16. 手机短信(SMS)工作原理(一)
  17. 网站流量分析的整体思路(大数据)
  18. 三星手机「我的文件」应用闪退问题的解决方法
  19. springboot二手车交易系统毕业设计源码131456
  20. 吴恩达《深度学习》课程介绍

热门文章

  1. scanf与scanf_s的区别
  2. win10系统cf连接服务器失败,cf与服务器连接失败
  3. 案例分析 2 :系统建模或数据库设计
  4. 景点查询系统c语言程序,《C语言程序设计》课程计报告-景点查询系统.doc
  5. 面向对象IOS编程中的聚合与耦合
  6. 计算机策略编辑器,Windows系统打开组策略编辑器的多种方法图文教程
  7. 记录版本更新安装时解析包报错
  8. 入职3个月的Java程序员面临转正,领导:1年工作经验包装成5年,试用期淘汰!
  9. 录音笔生成文件自动传到服务器,如何在Linux下设置录音笔时间
  10. 深度学习有哪些SCI期刊推荐? - 易智编译EaseEditing