hdu 1217 Arbitrage (spfa算法)
题目链接: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算法)的更多相关文章
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- hdu 1217 Arbitrage (最小生成树)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1217 /************************************************* ...
- HDU 1217 Arbitrage (Floyd)
Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...
- hdu 1217 Arbitrage(佛洛依德)
Arbitrage Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- hdu 1217 利用flord算法求 有环图 2点之间最大值
Arbitrage T ime Limit: 2000/1000 MS (Java/Other ...
- HDU 1217 Arbitrage(Bellman-Ford判断负环+Floyd)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 题目大意:问你是否可以通过转换货币从中获利 如下面这组样例: USDollar 0.5 Brit ...
- [ACM] hdu 1217 Arbitrage (bellman_ford最短路,推断是否有正权回路或Floyed)
Arbitrage Problem Description Arbitrage is the use of discrepancies in currency exchange rates to tr ...
- HDU 2112 HDU Today <SPFA算法+map函数>
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 1217 Arbitrage
Flody多源最短路 #include<cstdio> #include<cstring> #include<string> #include<cmath&g ...
随机推荐
- ZOJ 2072 K-Recursive Survival
https://vjudge.net/contest/67836#problem/K n people numbered 1 to n around a circle, we eliminate ev ...
- RabbitMQ安装与初始配置【转载】
Erlang安装 rabbitmq依赖于Erlang,需先安装,推荐安装rabbitmq/erlang-rpm: #clone源码 git clone https://github.com/rabbi ...
- 【Docker 命令】- exec命令
docker exec :在运行的容器中执行命令 语法 docker exec [OPTIONS] CONTAINER COMMAND [ARG...] OPTIONS说明: -d:分离模式: 在后台 ...
- SFTPHelper
public class SFTPHelper { #region 字段或属性 private readonly SftpClient _sftp; /// <summary> /// S ...
- SQL 中 Date 与Datetime的区别
Date是SQL Server 2008新引进的数据类型.它表示一个日子,不包含时间部分,可以表示的日期范围从公元元年1月1日到9999年12月31日.只需要3个字节的存储空间. DateTime 日 ...
- window 安装 nvm
下载地址 https://github.com/coreybutler/nvm-windows/releases 设置淘宝镜像 nvm node_mirror https://npm.taobao.o ...
- CentOS 查看系统内核和版本
1.uname 命令用于查看系统内核与系统版本等信息,格式为“uname [-a]”. [root@bigdata-senior01 ~]# uname -a Linux bigdata-senior ...
- 【题解】CF#855 G-Harry Vs Voldemort
个人感觉挺有意思的,然而被颜神D无聊惹(- ̄▽ ̄)- 这题我们可以首先试图去统计以每一个点作为 w 点所能对答案造成的贡献是多少.不难发现,当且仅当 u 和 v 都在 w 所在边双的一侧的时候不能构成 ...
- [LouguT30212]玩游戏
题面在这里 description 对于\(k=1,2,...,t\),求\[\frac{1}{nm}\sum_{i=1}^{n}\sum_{j=1}^{m}(a_i+b_j)^k\] 对\(9982 ...
- Matrix.(POJ-2155)(树状数组)
题目是让每次对一个子矩阵进行翻转(0变1,1变0), 然后有多次询问,询问某个点是0还是1 这题可以用二维的树状数组来解决,考虑传统的树状数组是改变某个点,然后查询某一段, 而这个题是改变某一段,查询 ...