hdu 1217 Arbitrage
Flody多源最短路
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<algorithm>
#include<iostream>
using namespace std; const int maxn=;
map<string,int>zh;
string s,s1,s2;
double jz[maxn][maxn],A[maxn][maxn];
int u,v,n,m; void floyd()
{
int i,j,k;
for(i=;i<=n;i++) for(j=;j<=n;j++) A[i][j]=jz[i][j];
for(k=;k<=n;k++)
{
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
if(k==i||k==j) continue;
if(A[i][k]*A[k][j]>A[i][j]) A[i][j]=A[i][k]*A[k][j];
}
}
}
} int main()
{
int i,j,_=; double cost;
while(~scanf("%d",&n))
{
if(!n) break; zh.clear();
for(i=;i<=n;i++) {cin>>s;zh[s]=i;}
scanf("%d",&m);
memset(jz,,sizeof(jz));
for(i=;i<m;i++)
{
cin>>s1; scanf("%lf",&cost); cin>>s2;
u=zh[s1];v=zh[s2];
jz[u][v]=cost;
}
int flag=;
floyd();
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
if(A[i][j]*A[j][i]>1.0) {flag=;break;}
}
if(flag) break;
}
printf("Case %d: ",_++);
if(flag) printf("Yes\n");
else printf("No\n");
}
return ;
}
hdu 1217 Arbitrage的更多相关文章
- 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 (Floyd)
Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...
- hdu 1217 Arbitrage (最小生成树)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1217 /************************************************* ...
- HDU 1217 Arbitrage(Bellman-Ford判断负环+Floyd)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 题目大意:问你是否可以通过转换货币从中获利 如下面这组样例: USDollar 0.5 Brit ...
- hdu 1217 Arbitrage (spfa算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 题目大意:通过货币的转换,来判断是否获利,如果获利则输出Yes,否则输出No. 这里介绍一个ST ...
- [ACM] hdu 1217 Arbitrage (bellman_ford最短路,推断是否有正权回路或Floyed)
Arbitrage Problem Description Arbitrage is the use of discrepancies in currency exchange rates to tr ...
- hdu 1217 Arbitrage(佛洛依德)
Arbitrage Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- HDU 1217 Arbitrage(Floyd的应用)
给出一些国家之间的汇率,看看能否从中发现某些肮脏的......朋友交易. 这是Floyd的应用,dp思想,每次都选取最大值,最后看看自己跟自己的.....交易是否大于一.... #include< ...
- hdu 1217 (Floyd变形)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- 算法笔记_014:合并排序(Java)
1 问题描述 给定一组数据,使用合并排序得到这组数据的非降序排列. 2 解决方案 2.1 合并排序原理简介 引用自百度百科: 合并排序是建立在归并操作上的一种有效的排序算法.该算法是采用分治法(Div ...
- AngularCSS--关于angularjs动态加载css文件的方法(仅供参考)
AngularCSS CSS on-demand for AngularJS Optimize the presentation layer of your single-page apps by d ...
- 关于IO多路复用的一篇好文
http://blog.csdn.net/baixiaoshi/article/details/48708347 http://blog.csdn.net/hguisu/article/details ...
- xtrabackup 开启压缩备份
完整备份innobackupex --defaults-file=/etc/my.cnf --host=localhost --user=bkpuser --password=s3cret /data ...
- win8及win8.1商店出现0X80073CF9的解决办法!
//添加appinstallagent无效的方法 http://jingyan.baidu.com/article/e52e3615a2b38f40c60c51d3.html
- vue+webpack构建项目
概述 -- 项目中会用到的插件 vue-router vue-resource 打包工具 webpack 依赖环境 node.js start 安装vue开发的模板 # 全局安装 vue-cli $ ...
- [SOJ] Babelfish
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...
- 标准I/O 缓存
标准I/O提供了三种类型的缓存: (1)全缓存.在这种情况下,当填满标准I/O 缓存后才进行实际 I/O 操作.对于驻在磁盘上的文件通常是由标准I/O库实施全缓存的.在一个流上执行第一次I/O操作时, ...
- Uva 10780 Again Prime? No Time.(分解质因子)
题意:给你两个数m和n,问 n! 可以被 m^k 整除的k的最大值 思路:从这道我们可以想到n!末尾有多少个0的问题,让我们先想一下它的思想,我们找 n! 末尾有多少0, 实际上我们是在找n!中5的个 ...
- fiddler还是浏览器的问题
当我在浏览器里输入http://localhost/infomanage/price?cityid=1&cateid=246&timer=3 后端接收的参数是timer的时候,浏览器会 ...