Arbitrage

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

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
 
Source
 
 
         
只能感叹外国就连ACM比赛都是这么符合实际且实用啊。。。。。
题意:
        意思就是叫你算出银行的汇率,判断是否可以赚钱。。哈哈,当然这是非专业的。
        其实题目是告诉我们几个国家之间的汇率,然后叫我们判断他们之间是否有环。且最终通过这种转换能否赚钱。
 其实就是一个有关DP问题于是运用暴力的floyd就可以ko了。

#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的更多相关文章

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

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

  2. HDU 1217 Arbitrage (Floyd)

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

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

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

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

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

  5. hdu 1217 Arbitrage (spfa算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 题目大意:通过货币的转换,来判断是否获利,如果获利则输出Yes,否则输出No. 这里介绍一个ST ...

  6. [ACM] hdu 1217 Arbitrage (bellman_ford最短路,推断是否有正权回路或Floyed)

    Arbitrage Problem Description Arbitrage is the use of discrepancies in currency exchange rates to tr ...

  7. hdu 1217 Arbitrage(佛洛依德)

    Arbitrage Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  8. hdu 1217 Arbitrage

    Flody多源最短路 #include<cstdio> #include<cstring> #include<string> #include<cmath&g ...

  9. HDU 1217 Arbitrage(Floyd的应用)

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

随机推荐

  1. hibernate像MySQL数据库里面存值是中文乱码的解决合辑

    解决办法一: 1.把数据库表每一行改成gb2312_chinese(使用PHPMyAdmin)   2.导入时候还是不行,因此查网上的资料说hibernate持久化层在传输过程中未设置编码格式,这样在 ...

  2. ORACLE主要的系统表和系统视图

    ORACLE主要的系统表和系统视图 1.系统表 ORACLE数据库的系统参数都存储在数据库中,可以通过SQLPLUS,以用户SYS进行查询.几个重要的表或者视图如下: v$controlfile:控制 ...

  3. Jquery实现日期格式化

    格式一:yyyy-MM-dd HH:mm:ss Date.prototype.format = function(format) { /* * eg:format="yyyy-MM-dd h ...

  4. web标准(复习)--8

    今天我们开始学习下拉及多级弹出菜单,包含以下内容和知识点: 带下拉子菜单的导航菜单 绝对定位和浮动的区别和运用 css自适应宽度滑动门菜单 一.带下拉子菜单的导航菜单下拉菜单在一些企业网站应用尤为广泛 ...

  5. 指针与数组、大小端之 printf("%x,%x,%x\n",*(a+1),ptr1[-1],*ptr2);

    在X86系统下,以下程序输出的值为多少? #include <stdio.h> #include <stdlib.h> int main(void) { ]={,,,,}; ) ...

  6. C C++ OC iOS面试重点问题(一)

    C C++ OC iOS面试重点问题(一) 1.字符串常量需要加\0 2.逻辑运算 位操作(经典:实现两个数的交换) 3.关键字 4.引用和指针的区别和联系 5.如何引用一个已经定义过的全局变量?  ...

  7. 基于toyix的进程和轻权进程的学习

    我们在平时的计算机课上学习过进程,知道程序的执行的背后其实就是进程在进行一些操作.大家都知道打开windows的任务管理器可以看到正在运行的进程,当程序卡死时,可以在任务管理器里强制关闭相关程序的进程 ...

  8. TranslateAnimation详解

    TranslateAnimation详解 Android JDK为我们提供了4种动画效果,分别是: AlphaAnimation,RotateAnimation, ScaleAnimation, Tr ...

  9. netstat命令, netstat指令在windows和linux有什么不同

    查看当前tcp监听端口[op@TIM html]$ netstat -nltp(Not all processes could be identified, non-owned process inf ...

  10. ASP.NET文件组成(转载于Owen的BLOG)

    一.扩展名: .aspx:窗体文件,为前台程序. .cs文件:类文件,主要为后台数据处理,供所有的.aspx文件的后台应用. .asmx文件:用于创建从其他应用程序使用的web服务的类. .css文件 ...