题目链接: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. Activemq 消息类型 (转)

    Activemq消息类型JMS规范中的消息类型包括TextMessage.MapMessage.ObjectMessage.BytesMessage.和StreamMessage等五种.ActiveM ...

  2. Python2中编码错误---重组人表皮生长因子凝胶(易孚格式转化为UTF-8

    在python2的使用中,总会遇到各种各样的编码问题,这也是使用Python2最头疼的一件事情,幸好python3解决了编码的问题. 下面我在爬虫时遇到的类似重组人表皮生长 ...

  3. [Leetcode] 3.Longest Substring Without Repeating Characters(unordered_map)

    通过把未访问的结点放到unordered_map中来判断是否重复,代码如下: class Solution { public: int lengthOfLongestSubstring(string ...

  4. [Leetcode] 2.Add Two Numbers(List To Long,模拟)

    本题题意是指将两个数倒序存储在链表中,再将两数之和同样存储在链表中输出. 我最开始的思路是将每一位相加,再考虑是否进位,但这时就需要考虑一些情况,比较麻烦. 于是我决定采取另一种在网上新学到的方法:这 ...

  5. codeforces 987 D. Fair

    D. Fair time limit per test 2 seconds memory limit per test 512 megabytes input standard input outpu ...

  6. 实用图像处理入门 - 1 - opencv VS2012 环境搭建

    标签中的部分 font-family: 华文细黑; font-size: 26px; font-weight: bold; color: #611427; margin-top:40px; } h2 ...

  7. P2580 于是他错误的点名开始了

    题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉(详情请见已结束比赛CON900). ...

  8. 【题解】51nod 1685第K大区间2

    二分答案+++++++(。・ω・。) 感觉这个思路好像挺常用的:求第\(K\) 大 --> 二分第 \(K\) 大的值 --> 检验当前二分的值排名是第几.前提:排名与数值大小成单调性变化 ...

  9. 【刷题】BZOJ 1002 [FJOI2007]轮状病毒

    Description 轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生的.一个N轮状基由圆环上N个不同的基原子 和圆心处一个核原子构成的,2个原子之间的边表示这2个原子之间的信息通道.如下 ...

  10. BZOJ2049:[SDOI2008]洞穴勘测——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=2049 https://www.luogu.org/problemnew/show/P2147 辉辉热 ...