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. Tomcat配置远程调试端口(windows、Linux)

    当我们需要定位生产环境问题,而日志又不清晰的情况下,我们可以借助Tomcat提供的远程调试,设置如下: // Linxu系统: apach/bin/startup.sh开始处中增加如下内容: decl ...

  2. 金老师的经典著作《一个普通IT人的十年回顾》

    学习人生             -------一个普通IT人的十年回顾(上)序从1994到2003,不知不觉之间,我已在计算机技术的世界里沉浸了十年.有位哲人说过:如果一个人能用十年的时间专心致志地 ...

  3. Oracle性能优化5-索引的不足

    索引的不足 1.索引开销 a.访问开销   反问集中导致热块的竞争(对最新数据的查询)   回表性能取决聚合因子   索引的访问开销,返回几条数据快,但是返回大量的数据很慢   全表扫描与全扫描   ...

  4. C# oracle to_date 日期型 参数传值

    C#操作oracle,date字段,使用参数传值 例子一,获取三小时前的记录 public static DataTable Query() {     const string sSql = &qu ...

  5. C# 通过api函数GetPrivateProfileString读取ini文件,取不到值

    通过api函数GetPrivateProfileString读取ini文件,取不到值,测试了好长时间,都不行 确认程序,ini文件都没有错误的情况,最后发现是ini文件编码的原因. 将ini文件的编码 ...

  6. String 练习

    package com.hanqi; import java.util.Random; public class Text { public static void main(String[] arg ...

  7. *jQuery选择器总结(原创:最全、最系统、实例展示)

    jquery选择器包括四部分:一.基本选择器二.层次选择器三.过滤选择器四.表单元素选择器 一.基本选择器1.ID选择器:$('#myDiv');2.类选择器:$('.className');3.元素 ...

  8. “Interrupted by header callback: Server reports Content-Length”如何解决

    mock初始化时的错误信息如下: Downloading Packages: [SKIPPED] systemd--.fc25.x86_64.rpm: Already downloaded [SKIP ...

  9. 原生和web交互jsbridge交互总结

    技术点:jsbridge. 一: 参数及其意义(代码意义结合支付项目) 二:主动请求原生参数与方法(sendapi) 参数1 判断接口类型 参数2 传递给原生的数据 参数3 回调函数,response ...

  10. c# 反编译后窗口控件在vs中打不开的修改方法

    DialogResult.Cancel System.Windows.Forms.DialogResult.Cancel DialogResult.OK System.Windows.Forms.Di ...