给出一些国家之间的汇率,看看能否从中发现某些肮脏的......朋友交易。

这是Floyd的应用,dp思想,每次都选取最大值,最后看看自己跟自己的.....交易是否大于一。。。。

#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<map>
using namespace std;
#define exp 0.00000001
map<string,int>ma;
double dp[][];
bool Equal(double a,double b)
{
if(a-b > exp) return true;
return false;
}
int main()
{
int n,ca = ;
while(~scanf("%d",&n) && n)
{
string a;
ma.clear();
memset(dp,,sizeof(dp));
for(int i = ;i <= n;i++)
{
cin >> a;
ma[a] = i;
dp[i][i] = ;
}
int m;
scanf("%d",&m);
for(int i = ;i <= m;i++)
{
string fr,to;
int fr1,to1;
double k;
cin>>fr>>k>>to;
fr1 = ma[fr],to1 = ma[to];
dp[fr1][to1] = k;
}
for(int k = ;k <= n;k++)
{
for(int i = ;i <= n;i++)
{
for(int j = ;j <= n;j++)
dp[i][j] = max(dp[i][j],dp[i][k] * dp[k][j]);
}
}
bool flag = true;
for(int i = ;i <= n;i++)
{
if(Equal(dp[i][i],1.0))
{
flag = false;
break;
}
}
printf("Case %d: ",++ca);
if(flag) printf("No\n");
else printf("Yes\n");
}
return ;
}

HDU 1217 Arbitrage(Floyd的应用)的更多相关文章

  1. HDU 1217 Arbitrage (Floyd)

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

  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. hdu 1217 (Floyd变形)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others)   ...

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

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

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

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

  6. hdu 1217 Arbitrage (spfa算法)

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

  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 汇率 Floyd

    题意:给几个国家,然后给这些国家之间的汇率.判断能否通过这些汇率差进行套利交易. Floyd的算法可以求出任意两点间的最短路径,最后比较本国与本国的汇率差,如果大于1,则可以.否则不可以. 有向图 一 ...

随机推荐

  1. hdu_5783_Divide the Sequence(贪心)

    题目链接:hdu_5783_Divide the Sequence 题意: 给你一个数列,让你分尽可能多的段,并且保证每一段的前缀和都不小于0 题解: 从后往前xjb贪心就行了 #include< ...

  2. LeetCode OJ 66. Plus One

    Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...

  3. iOS使用NSMutableAttributedString

    在iOS开发中,常常会有一段文字显示不同的颜色和字体,或者给某几个文字加删除线或下划线的需求.之前在网上找了一些资料,有的是重绘UILabel的textLayer,有的是用html5实现的,都比较麻烦 ...

  4. Linux设置静态IP【转】

    一只小码 2016-08-16 10:32 测试服务器OS: Centos 6.5 x64 本机OS: Ubuntu 14.04 x64 由于Virtualbox当时安装Centos 6.5的时候设置 ...

  5. 去掉input text后面的叉

    如题 input[type=text]::-ms-clear{ display: none; } input::-webkit-search-cancel-button{ display: none; ...

  6. android之DPAD上下左右四个键控制

    我们代码的目的很简单,那就是监听上下左右中这几个键的事件触发.直接上代码: dpad.xml <?xml version="1.0" encoding="utf-8 ...

  7. rownum使用方法

    rownum使用方法: .使用rownum子查询: rownum是一个总是从1开始的伪列,当查询条件rownum)时,不能从数据库查到记录,因此要 通过子查询解决:; 结果: SQL; R ID US ...

  8. yum no key

    http://serverfault.com/questions/525958/redhat-yum-install-gpg-key-retrieval-failed

  9. linux 终端相关

    echo cd ~/桌面 >> .bashrc 将终端默认路径设为桌面 -/.bashrc./etc/bash.bashrc./etc/profile这几个文件.这些文件的的作用时机:/e ...

  10. mysql 初始化时root无密码

    修改密码 update user set password=PASSWORD('123456') where User='root'; 添加用户设置权限 grant select,insert,upd ...