链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217

Arbitrage

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4430    Accepted Submission(s): 2013

Problem 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 file 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
 
----------------------------------------------------------------------------
================================================
题意自己看吧,Floyd的变形,求出每个点到自己的最大权值,并且用乘法不是加法
用了map容器便于操作
 
 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <map> #define MAXX 35
#define INF 1000000000
double d[MAXX][MAXX];
using namespace std; void Flody(int n)
{
int i,j,k;
for(k=; k<n; k++)
for(i=; i<n; i++)
for(j=; j<n; j++)
if(d[i][k] * d[k][j] > d[i][j])
d[i][j] = d[i][k] * d[k][j];
} int main()
{
int n,i,j,t,tmp=;
while(scanf("%d",&n)!=EOF&&n)
{
char str[],str1[],str2[];
int cas=;
double rate;
map<string,int> m;
map<string,int>::iterator it;
for(i=; i<n; i++)
for(j=; j<n; j++)
d[i][j] = ;
for(i=; i<n; i++)
{
scanf("%s",str);
m[str]=cas++;
}
scanf("%d",&t);
for(i=; i<t; i++)
{
scanf("%s%lf%s",str1,&rate,str2);
d[m[str1]][m[str2]]=rate;
}
Flody(n);
bool flag=false;
for(i=; i<n; i++)
{
if(d[i][i]>1.0)
{
flag=true;
break;
}
}
if(flag)
{
printf("Case %d: Yes\n",++tmp);
}
else
{
printf("Case %d: No\n",++tmp);
}
}
return ;
}
 

hdu 1217 (Floyd变形)的更多相关文章

  1. hdu 1217 Arbitrage (最小生成树)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1217 /************************************************* ...

  2. UVA10048 Audiophobia[Floyd变形]

    UVA - 10048 Audiophobia Consider yourself lucky! Consider yourself lucky to be still breathing and h ...

  3. POJ2253——Frogger(Floyd变形)

    Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...

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

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

  5. hdu 1596(Floyd 变形)

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...

  6. HDU 1217 Arbitrage (Floyd)

    Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...

  7. HDU 1217 Arbitrage(Bellman-Ford判断负环+Floyd)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 题目大意:问你是否可以通过转换货币从中获利 如下面这组样例: USDollar 0.5 Brit ...

  8. HDU 4034 Graph(Floyd变形——逆向判断)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4034 Problem Description Everyone knows how to calcu ...

  9. HDU 1217 Arbitrage(Floyd的应用)

    给出一些国家之间的汇率,看看能否从中发现某些肮脏的......朋友交易. 这是Floyd的应用,dp思想,每次都选取最大值,最后看看自己跟自己的.....交易是否大于一.... #include< ...

随机推荐

  1. sql字段类型介绍

    1 表格与储存引擎 表格(table)是数据库中用来储存纪录的基本单位,在建立一个新的数据库以后,你必须为这个数据库建立一些储存资料的表格: 每一个数据库都会使用一个资料夹,这些数据库资料夹用来储存所 ...

  2. js 中的call()函数

    a.call(b); 官方说:什么对象替换什么对象. a对象的方法应用到b对象上(函数apply的意思正好说明符合这样理解:a对象应用到b对象上去) a对象既然添加到b对象上了.那么b对象自然就拥有了 ...

  3. MySQL Replication 优化和技巧、常见故障解决方法

    MySQL 主从同步错误(error)解决(转) sql_slave_skip_counter参数 附: 一些错误信息的处理,主从服务器上的命令,及状态信息. 在从服务器上使用show slave s ...

  4. Hibernate,JPA注解@ManyToMany

    @ManyToMany默认处理机制,当双向多对多关联中没有定义任何物理映射时, Hibernate根据以下规则生成相应的值: 关联表名: 主表表名+_下划线+从表表名: 关联到主表的外键名:从表用于关 ...

  5. HDU 4635:Strongly connected(强连通)

    http://acm.hdu.edu.cn/showproblem.php?pid=4635 题意:给出n个点和m条边,问最多能添加几条边使得图不是一个强连通图.如果一开始强连通就-1.思路:把图分成 ...

  6. hdwiki中插件开发指南

    插件就是为了满足个性化需求按照HDWiki插件开发规范编写的可插拔程序,虽然可以直接对HDWiki进行二次开发实现插件同样的功能,但是这样做势必影响到系统的升级和稳定性. 采用插件的方式,可以随时进行 ...

  7. git简介及安装配置

    Git是一种分布式版本控制系统.它和集中式版本控制系统的区别有如下几点: 1).分布式版本控制没有中央服务器,每个人的电脑上都有完整的版本库: 2).分布式管理系统的安全性要高,如果某一台电脑的坏了, ...

  8. Java可变长参数方法调用问题

    不说废话,直接上代码: package mytest; import java.util.List; public class TestClass { public void method(List& ...

  9. 简单LRU算法实现缓存

    最简单的LRU算法实现,就是利用jdk的LinkedHashMap,覆写其中的removeEldestEntry(Map.Entry)方法即可,如下所示: java 代码 import java.ut ...

  10. noi 7627 鸡蛋的硬度

    题目链接:http://noi.openjudge.cn/ch0206/7627/ 题目讲的二分其实是一个误导, d(i,j),表示当前最优策略时,最坏的情况下: 有 J 个鸡蛋,I 个可以怀疑的楼层 ...