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

题目大意:通过货币的转换,来判断是否获利,如果获利则输出Yes,否则输出No。

这里介绍一个STL中的map容器去处理数据,map<string,int>V,M;

现在我目前的理解是将字符串转换成数字,然后就是根据spfa的模板找最短路了。。哇哈哈( ⊙o⊙ )哇

 #include <iostream>
#include <cstdio>
#include <map>
#include <queue>
#include <cstring>
using namespace std;
int n,a;
double Map[][];
const int INF=;
map<string,int>V; int spfa()
{
queue<int>q;
double node[]= {};
int inq[]= {};
node[]=;
inq[]=;
q.push();
while (!q.empty())
{
int s=q.front();
q.pop();
for (int i=; i<=n; i++)
{
//cout<<Map[s][i]<<" "<<node[i]<<endl;
if (node[i]<Map[s][i]*node[s])
{
//cout<<node[i]<<" "<<Map[s][i]<<endl;
node[i]=Map[s][i]*node[s];
if (!inq[i])
{
q.push(i);
inq[i]=;
}
if (node[]>)
return ;
} }
inq[s]=;
}
return ;
}
int main ()
{
char ch[];
int cmp=,q;
while (scanf("%d",&n),n)
{
q=;
V.clear();
for (int i=; i<=n; i++)
for (int j=; j<=n; j++)
Map[i][j]=;
//memset(Map,INF,sizeof(Map));
for (int i=; i<=n; i++)
{
scanf("%s",ch);
if (!V[ch])
V[ch]=++q;
}
scanf("%d",&a);
for (int i=; i<=a; i++)
{
double money;
char ch1[],ch2[];
scanf("%s%lf%s",ch1,&money,ch2);
if (Map[V[ch1]][V[ch2]]<money)
Map[V[ch1]][V[ch2]]=money;
//cout<<Map[V[ch1]][V[ch2]]<<endl;
}
printf ("Case %d: ",cmp++);
if (spfa())
printf("Yes\n");
else
printf ("No\n");
}
return ;
}

hdu 1217 Arbitrage (spfa算法)的更多相关文章

  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 (最小生成树)

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

  3. HDU 1217 Arbitrage (Floyd)

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

  4. hdu 1217 Arbitrage(佛洛依德)

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

  5. hdu 1217 利用flord算法求 有环图 2点之间最大值

    Arbitrage                                                      T ime Limit: 2000/1000 MS (Java/Other ...

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

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

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

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

  8. HDU 2112 HDU Today &lt;SPFA算法+map函数&gt;

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. hdu 1217 Arbitrage

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

随机推荐

  1. exception = {"元数据集合中已存在具有标识“xxx”的项。\r\n参数名: item"}

    vs提示:exception = {"元数据集合中已存在具有标识"xxx"的项.\r\n参数名: item"} 出现这个错误说明有重复的字段,有可能是继承的类里 ...

  2. my.conf 修改编码

    mysql汉字乱码的原因 mysql默认的编码是Latin1是I-8859-1的别名,但Latin1是不支持汉字的,所以要将其改为UTF-8或GBK 1.关闭mysql服务器,这个很重要. 2.通过m ...

  3. linux tomcat shutdown.sh 不能正常关闭

    一般造成这种原因是因为项目中有非守护线程的存在 基本原理为启动tomcat时记录启动tomcat的进程id(pid),关闭时强制杀死该进程 1.找到tomcat下bin/catalina.sh文件,v ...

  4. Android------BottonTabBar

    前言:一款简单好用封装好的AndroidUI控件,底部导航栏. 1.使用 1.1添加  compile 'com.hjm:BottomTabBar:1.1.1' 1.2  activity_main. ...

  5. [OS] 进程互斥

    对互斥的正确软件实现算法(面包店算法)是非常耗时的,现代的计算机系统都会提供简单的硬件指令,使用这些指令能够有效地解决临界区问题. 硬件提供一个TestAndSet指令,来实现原子指令的功能: boo ...

  6. 【Todo】【转载】JVM学习

    先参考如下这个系列<聊聊JVM> http://blog.csdn.net/column/details/talk-about-jvm.html

  7. 具体数学二项式至生成函数章-----致敬Kunth

    关于标题取得这么奇怪.因为在具体数学中.这两章是分开叙述的.并且分别叙述得淋漓尽致! 我只参悟其中关于生成函数的一小部分内容(暂时于我够用了.) 提二项式系数之前不得不提组合数.以往在高中用的是符号C ...

  8. Docker的结构(6-13)

    一.Docker的结构. Docker命令不清楚的时候可以在命令的最后加上--help Docker和虚拟机的区别? 虚拟机的实现原理是:先模拟出一套硬件,然后在这基础上跑一个操作系统,然后在这个操作 ...

  9. POJ1474:Video Surveillance——题解

    http://poj.org/problem?id=1474 题目大意:给按照顺时针序的多边形顶点,问其是否有内核. —————————————————————————————— (和上道题目一模一样 ...

  10. BZOJ3864 & HDU4899:Hero meet devil——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=3864 http://acm.hdu.edu.cn/showproblem.php?pid=4899 ...