题目链接: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. 编译android6.0错误recipe for target 'out/host/linux-x86/obj/lib/libart.so' failed

    转自:http://blog.csdn.net/ztguang/article/details/52856076 trip: libpagemap_32 (out/target/product/xx/ ...

  2. MySQL & export

    MySQL & export mysql export table form command line https://cn.bing.com/search?q=mysql%20export% ...

  3. Winform程序部署方式总结一——ClickOnce发布

    针对Winform程序,介绍两种常用打包方式:ClickOnce和Windows Installer 应用程序如下: 一.ClickOnce发布 1.找到需要发布的项目文件,右击,从弹出的快捷菜单中找 ...

  4. Tomcat 设计模式分析

    门面设计模式 门面设计模式在 Tomcat 中有多处使用,在 Request 和 Response 对象封装中.Standard Wrapper 到 ServletConfig 封装中.Applica ...

  5. 第43天:事件对象event

    一.事件对象事件:onmouseover. onmouseout. onclickevent //事件的对象 兼容写法:var event = event || window.event; event ...

  6. WPF数据视图学习

    当你绑定集合到ItemsControl,数据视图被安静地在幕后创造.视图位于数据源和绑定控件之间.数据视图是通往数据源的一个窗口.它跟踪当前项目,它支持诸如排序,过滤,和分组特征.这些特征独立于数据对 ...

  7. matlab imwrite

    函数功能:将图像数据写入到图像文件中,存储在磁盘上. 调用格式:imwrite(A,filename,fmt) A是图像数据,filename是目标图像名字,fmt是要生成的图片的格式. 图片格式有: ...

  8. connectedSignal 简单使用

    import java.util.concurrent.CountDownLatch; public class CountDown { private static CountDownLatch c ...

  9. P1491 集合位置

    题目描述 每次有大的活动,大家都要在一起“聚一聚”,不管是去好乐迪,还是避风塘,或者汤姆熊,大家都要玩的痛快.还记得心语和花儿在跳舞机上的激情与释放,还记得草草的投篮技艺是如此的高超,还记得狗狗的枪法 ...

  10. 【题解】CF#285 E-Positions in Permutations

    挺有收获的一道题ヾ(◍°∇°◍)ノ゙ 恰好为 m ,这个限制仿佛不是很好处理.一般而言,我所了解的恰好为 k 的条件,不是用组合数 / dp状态转移 / 斜率二分就只剩下容斥了.我们可以先处理出 nu ...