题目链接: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. Python实现FTP服务功能

    本文从以下三个方面, 阐述Python如何搭建FTP服务器 一. Python搭建FTP服务器 二. FTP函数释义 三. 查看目录结构 四. 上传下载程序 一. Python搭建FTP服务器 1. ...

  2. Jenkins系列-Jenkins插件备份

    Jenkins管理插件 为了让所有的插件在 Jenkins 内可用,所有插件的列表可以访问链接 − https://wiki.jenkins-ci.org/display/JENKINS/Plugin ...

  3. try-with-resources语句

    try-with-resources语句是一种声明了一种或多种资源的try语句.资源是指在程序用完了之后必须要关闭的对象.try-with-resources语句保证了每个声明了的资源在语句结束的时候 ...

  4. 使用户浏览器添加没有的字体@font-face

    @font-face的用法 @font-face { font-family: 'MyWebFont'; src: url('webfont.eot'); /* IE9 Compat Modes */ ...

  5. BZOJ 2326 数学作业(分段矩阵快速幂)

    实际上,对于位数相同的连续段,可以用矩阵快速幂求出最后的ans,那么题目中一共只有18个连续段. 分段矩阵快速幂即可. #include<cstdio> #include<iostr ...

  6. BZOJ 1202 狡猾的商人(带权并查集)

    给出了l,r,w.我们就得知了s[r]-s[l-1]=w.也就是说,点l-1和点r的距离为w. 于是可以使用带权并查集,定义dis[i]表示点i到根节点的距离.查询和合并的时候维护一下就OK了. 如果 ...

  7. BZOJ4735 你的生命已如风中残烛(组合数学)

    将每个位置上的数都-1,则显然相当于前缀和始终非负. 然后就是完全想不到的了.考虑往里面加一张-1的牌.假设在一个合法排列的最后添上一个-1,那么在该排列的所有循环同构排列中,满足前m个前缀和都非负的 ...

  8. vue-cli项目打包出现空白页和路径错误问题

    vue-cli项目打包: 1. 命令行输入:npm  run  build 打包出来后项目中就会多了一个文件夹dist,这就是我们打包过后的项目. 第一个问题,文件引用路径.我们直接运行打包后的文件夹 ...

  9. CentOS 不间断会话(ssh关闭后如何保证程序继续运行)(nohup和screen)

    当使用ssh与远程主机的会话被关闭时,在远程主机上运行的命令也随之被中断. 就是ssh 打开以后,bash等都是他的子程序,一旦ssh关闭,系统将所有相关进程杀掉!! 导致一旦ssh关闭,执行中的任务 ...

  10. 【题解】Atcoder ARC#90 F-Number of Digits

    Atcoder刷不动的每日一题... 首先注意到一个事实:随着 \(l, r\) 的增大,\(f(r) - f(l)\) 会越来越小.考虑暴力处理出小数据的情况,我们可以发现对于左端点 \(f(l) ...