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 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 题意:给出一些货币和货币之间的兑换比率,问是否可以使某种货币经过一些列兑换之后,货币值增加。
   举例说就是1美元经过一些兑换之后,超过1美元。可以输出Yes,否则输出No。
 #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define INF 9999999
#define MAX 300
int n;
float g[MAX][MAX];
char name[][];
int fun(char *str)
{
int i;
for(i=; i<=n; i++)
{
if(strcmp(name[i],str)==)
return i;
}
}
void FLOYD()
{
int i,j,k;
double t;
for(k=; k<=n; k++)
{
for(i=; i<=n; i++)
{
for(j=; j<=n; j++)
{
t=g[i][k]*g[k][j];
if(t>g[i][j])
g[i][j]=t;
if(g[i][j]>&&i==j)
{
printf("Yes\n");
return ;
}
}
}
}
printf("No\n");
}
int main()
{
int i,k=,m;
float t;
char str1[],str2[];
while(~scanf("%d",&n),n)
{
memset(g,,sizeof(g));
for(i=; i<=n; i++)
scanf("%s",&name[i]);
scanf("%d",&m);
for(i=; i<=m; i++)
{
scanf("%s %llf %s",str1,&t,str2);
g[fun(str1)][fun(str2)]=t;
}
printf("Case %d: ",++k);
FLOYD();
}
return ;
}

poj 2240 Arbitrage(最短路问题)的更多相关文章

  1. 最短路(Floyd_Warshall) POJ 2240 Arbitrage

    题目传送门 /* 最短路:Floyd模板题 只要把+改为*就ok了,热闹后判断d[i][i]是否大于1 文件输入的ONLINE_JUDGE少写了个_,WA了N遍:) */ #include <c ...

  2. POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)

    POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...

  3. poj 2240 Arbitrage 题解

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21300   Accepted: 9079 Descri ...

  4. poj 2240 Arbitrage (Floyd)

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

  5. POJ 2240 Arbitrage【Bellman_ford坑】

    链接: http://poj.org/problem?id=2240 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  6. POJ 2240 Arbitrage(floyd)

    http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...

  7. poj 2240 Arbitrage (最短路 bellman_ford)

    题目:http://poj.org/problem?id=2240 题意:给定n个货币名称,给m个货币之间的汇率,求会不会增加 和1860差不多,求有没有正环 刚开始没对,不知道为什么用 double ...

  8. POJ 2240 Arbitrage(判正环)

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

  9. poj 2240 Arbitrage(Bellman_ford变形)

    题目链接:http://poj.org/problem?id=2240 题目就是要通过还钱涨自己的本钱最后还能换回到自己原来的钱种. 就是判一下有没有负环那么就直接用bellman_ford来判断有没 ...

随机推荐

  1. 当前上下文中不存在viewbag

    参考链接:http://www.cnblogs.com/chas/p/5076297.html view文件夹下的web.config中的appsetting节点中缺少了 <add key=&q ...

  2. 包含了重复的“Content”项。.NET SDK 默认包含你项目目录中的“Content”项。可从项目文件中删除这些项;如果希望将其显式包含在项目文件中,可将“EnableDefaultContentItems”属性设置为“false”

    从.netcore 1.1 升级到2.0时遇到该问题. 参考http://www.cnblogs.com/xishuai/p/visual-studio-for-mac.html 根据提示可知(我是看 ...

  3. JAVA软件安装

    Java配置----JDK开发环境搭建及环境变量配置 文章来源:http://www.cnblogs.com/smyhvae/p/3788534.html Tomcat安装.配置和部署笔记 文章来源: ...

  4. VSS源代码管理器运行代码分析工具的命令

    当你发现代码库总是报需要联系管理员运行代码分析工具时,你可以使用命令分析代码库代码解决: To fix the database problems, you can restart the analy ...

  5. 2.git使用之git fetch和git push的区别

    . git fetch:相当于是从远程获取最新版本到本地,不会自动merge git fetch origin master git log -p master..origin/master git ...

  6. Oracle_PL/SQL(8) 动态sql

    动态sql0.pl/sql块的限制 不能执行ddl操作(create.drop.alter): 不能执行部分dcl操作(grant.revoke). 1.语法动态sql:在执行时才能确定要执行的sql ...

  7. 虚拟机vmware centos7 扩展磁盘空间

    0.思路 创建一个新的逻辑分区,将新的逻辑分区格式化ext3(或其他类型)的文件系统,mount到磁盘空间不够的文件系统,就跟原来的分区/文件系统一样的使用 1.准备 1.1 注意使用VMware自带 ...

  8. js 闭包 弊端

    闭包有许多有趣的用途,Javascript的两个特征使它这么有趣:1. function是一个对象,它跟数组,Object一样,地位平等.2. Javascript变量作用域范围.<Javasc ...

  9. Python代码运行应该注意哪些问题?

    Python作为近年来热度一度高涨的编程语言,非常受广大程序员的喜爱,用过之后发现这门语言有很多特点.比如作为一门动态语言它的变量是信手拈来就可以用的,甚至比js还简单,也没有编程语言常见的大括号包含 ...

  10. 找不到或无法加载主类(Could not find or load main class )

    在Linux环境下,写了一个简单的java程序,通过javac编译成class文件,然后用java 运行的时候,报了这个错误, 搜了一下,可能是classpath的问题,所以用echo $CLASSP ...