Arbitrage HDU
Arbitrage
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3180 Accepted Submission(s): 1445
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.
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.
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
Case 2: No
只能感叹外国就连ACM比赛都是这么符合实际且实用啊。。。。。
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cstdio>
#include <cstring>
using namespace std; double dp[31][31];
bool Floyd(int n)
{
for(int k = 1;k <= n;k++)
for(int i = 1;i <= n;i++)
for(int j = 1;j <= n;j++)
dp[i][j] = max(dp[i][j],dp[i][k]*dp[k][j]);
for(int i = 1;i <= n;i++)
if(dp[i][i] > 1)
return true;
return false;
} int main()
{
double rate;
int n,m,i,kase = 1;
while(cin>>n,n)
{
string s,a,b;
map<string,int> mp;
memset(dp,0,sizeof(dp));
for(i = 1;i <= n;i++)
{
cin>>s;
mp[s] = i;
}
cin>>m;
for(i = 1;i <= m;i++)
{
cin>>a>>rate>>b;
dp[mp[a]][mp[b]] = rate;
}
if(Floyd(n))
printf("Case %d: Yes\n",kase++);
else
printf("Case %d: No\n",kase++);
}
return 0;
}
Arbitrage HDU的更多相关文章
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- HDU 1217 Arbitrage (Floyd)
Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...
- hdu 1217 Arbitrage (最小生成树)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1217 /************************************************* ...
- HDU 1217 Arbitrage(Bellman-Ford判断负环+Floyd)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 题目大意:问你是否可以通过转换货币从中获利 如下面这组样例: USDollar 0.5 Brit ...
- hdu 1217 Arbitrage (spfa算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 题目大意:通过货币的转换,来判断是否获利,如果获利则输出Yes,否则输出No. 这里介绍一个ST ...
- [ACM] hdu 1217 Arbitrage (bellman_ford最短路,推断是否有正权回路或Floyed)
Arbitrage Problem Description Arbitrage is the use of discrepancies in currency exchange rates to tr ...
- hdu 1217 Arbitrage(佛洛依德)
Arbitrage Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- hdu 1217 Arbitrage
Flody多源最短路 #include<cstdio> #include<cstring> #include<string> #include<cmath&g ...
- HDU 1217 Arbitrage(Floyd的应用)
给出一些国家之间的汇率,看看能否从中发现某些肮脏的......朋友交易. 这是Floyd的应用,dp思想,每次都选取最大值,最后看看自己跟自己的.....交易是否大于一.... #include< ...
随机推荐
- angular ng-bind-html 对src路径失效 解决方案
json内容 ;<img src="/newsfile/1506271512489.jpg" width="600" height="450&q ...
- php目录分隔符DIRECTORY_SEPARATOR
在windows我们习惯性的使用“\”作为文件分隔符,但是在linux上系统不认识这个标识,于是就要引入这个php内置变量了:DIRECTORY_SEPARATOR 路径分隔符 windows \ o ...
- UIApplication详解再解-备
每个app有且只有一个UIApplication对象,当程序启动的时候通过调用UIApplicationMain方法得到的.可以通过sharedApplication方法得到. UIApplicati ...
- 酷狗、QQ、天天动听——手机音乐播放器竞品对比
如果说什么艺术与人们生活最贴近,那应该属音乐了,因此当代人不离身的手机里必然会有自己喜欢的音乐播放器APP存在. 在当今无论PC端还是手机端音乐播放器都越来越同质化,我们应该选择哪款手机音乐播放器?它 ...
- MVC3路由设置访问后缀 html jsp
C# Code 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 publ ...
- windows设备驱动安装指南
高观点下的设备驱动安装(overview) 一.windows是怎样安装设备的? 第一步:新设备的识别 在给一个新设备安装驱动之前,总线或集线器(hub)驱动会为连接到PC上的设备分配一个硬件ID(h ...
- [VBA] excel获取单元格的超链接地址函数
Function geturl(c As Range) As String geturl = c.Hyperlinks().Address End Function 设置超链接的函数是HYPERLIN ...
- Codeforces Round #322 (Div. 2) —— F. Zublicanes and Mumocrates
It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The ...
- paip.sql索引优化----join 代替子查询法
paip.sql索引优化----join 代替子查询法 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.n ...
- C# 二分查询
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...