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

/************************************************************************/
/*
hdu Arbitrage
floyd求最短路径
题目大意:floyd算法,求得两点之间最短距离,(u,v) = min( (u,v),(u,w)+(w,v) );
    此题,是求其能够赚钱,即最大生成树,且过程是相乘的,公式:( u, v) = max( (u,v), (u,w)*(w,v) );
*/
/************************************************************************/ #include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <algorithm>
#include <cmath> using namespace std; #define MIN(a,b) a<b?a:b
#define MAX 0xfffffff const int N = ;
double maps[N][N];
int num,key;
map<string,int> hash_map; void build_map()
{
char name[],name1[];
double rate;
int m;
for (int i = ; i <= num; i++)
{
scanf("%s",name);
hash_map[name] = i;
}
memset(maps,,sizeof(maps));
scanf("%d",&m);
for (int i = ; i < m; i++)
{
scanf("%s%lf%s",name,&rate,name1);
maps[hash_map[name]][hash_map[name1]] = rate;
} } void fload()
{
for (int k = ; k <= num; k++)
{
for (int i = ; i <= num; i++)
for (int j = ; j <= num; j++)
maps[i][j] = max(maps[i][j],maps[i][k] * maps[k][j]);
}
int j;
for (j = ; j <= num; j++)
if (maps[j][j] > )break;
if (j>num)printf("Case %d: No\n",key);
else printf("Case %d: Yes\n",key);
hash_map.clear();
} int main()
{
key = ;
while(scanf("%d",&num) && num != )
{
key++;
build_map();
fload();
}
return ;
}

hdu 1217 Arbitrage (最小生成树)的更多相关文章

  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(Bellman-Ford判断负环+Floyd)

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

  4. hdu 1217 Arbitrage (spfa算法)

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

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

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

  6. hdu 1217 Arbitrage(佛洛依德)

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

  7. hdu 1217 Arbitrage

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

  8. HDU 1217 Arbitrage(Floyd的应用)

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

  9. hdu 1217 (Floyd变形)

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

随机推荐

  1. 设置char变量指定位为0或1

    int GetBit(char c,int i)//取c的第i位 { ; } void SetBit(char & c,int i, int v)//设置c的第i位为v,v是0或1 { if( ...

  2. PLSQL创建DBLINK

    Oracle创建dblink,多用于数据的同步机制.不建议直接用dblink对数据库频繁的操作... 00.查看创建dblink权限 select * from user_sys_privs t wh ...

  3. C++基础学习教程(六)----类编写的前情回想以及项目实战(1)

    在開始类的编写之前我们依旧须要回想整理一下前面所说的内容,(前面尽管是一个自己定义数据类型的实现过程,可是内容有点繁杂). 先看一段代码: /** @file calssStruct.cpp */ / ...

  4. 解决CSS的position:absolute中left效果

    有时候css中设置了position:absolute,left:100px,但是如果我们不想要这个left怎么办呢,当然你直接删除就可以,但是如果是框架的css,你直接删除就有问题了,这时候该怎么办 ...

  5. PendingIntent传递数据注意参数RequestCode和Flag

    数据发送方: public static void notify(Context context, TxrjMessage msg) {     NotificationManager notifiM ...

  6. Android中使用DialogFragment来取代popopwindow

    DialogFragment +fragment 来取代popopwindow +fragment 先留个标题,这几天过来写,重大发现

  7. kubectl top查看k8s pod的cpu , memory使用率情况

    To see the pods that use the most cpu and memory you can use the kubectl top command but it doesn’t ...

  8. Oracle 9i 10g 11g 区别的转载

    下面看看9i.10g.11g版本的区别 Oracle 10g比9i多的新特性?        1. 10g支持网格计算,即多台结点服务器利用高速网络组成一个虚拟的高性能服务器,负载在整个 网格中衡(L ...

  9. Pycharm 中添加第三方库和插件

    在 PyCharm 中选择:File — Settings — 进入如下界面,点击 右上角的 “+” 可以添加其他库: 选择到相应的库,并 Install Package 即可:

  10. protobuf3 iOS 接入 protobuf

    1.引入官方基础pod 谷歌将protobuf需要使用的基础类封装成了一个pod,因此可以直接安装该pod,不必再手工导入. 如下: pod "Protobuf", :git =& ...