poj 2240 Arbitrage (最短路 bellman_ford)
题目:http://poj.org/problem?id=2240
题意:给定n个货币名称,给m个货币之间的汇率,求会不会增加
和1860差不多,求有没有正环
刚开始没对,不知道为什么用 double往结构体里传值的时候 会去掉小数点后的 数
- #include <iostream>
- #include<cstdio>
- #include<cstring>
- #include<cstdlib>
- #include<stack>
- #include<queue>
- #include<iomanip>
- #include<cmath>
- #include<algorithm>
- #include<map>
- using namespace std;
- struct node
- {
- int u,v;
- double w;
- }edge[];
- int cnt,n;
- double dis[];
- bool bellman_ford(int s)
- {
- int i,j;
- memset(dis,,sizeof(dis));
- dis[s] = ;
- for(i=; i<n-; i++)
- for(j=; j<cnt; j++)
- {
- int u=edge[j].u;
- int v=edge[j].v;
- double w=edge[j].w;
- if(dis[v]<dis[u]*w)
- dis[v]=dis[u]*w;
- }
- for(j=; j<cnt; j++)
- {
- int u=edge[j].u;
- int v=edge[j].v;
- double w=edge[j].w;
- if(dis[v]<dis[u]*w)
- return true;
- }
- return false;
- }
- int main()
- {
- map<string,int>mp;
- char s[],s2[],x=;
- int m,i,j;
- while(cin>>n&&n)
- {
- cnt=;
- for(i=; i<n; i++)
- {
- cin>>s;
- mp[s]=i;
- }
- cin>>m;
- for(i=; i<=m; i++)
- {
- cin>>s; scanf("%lf",&edge[cnt].w); cin>>s2;
- edge[cnt].u=mp[s]; edge[cnt].v=mp[s2];
- cnt++;
- }
- if(bellman_ford()) printf("Case %d: Yes\n",x++);
- else printf("Case %d: No\n",x++);
- }
- return ;
- }
poj 2240 Arbitrage (最短路 bellman_ford)的更多相关文章
- POJ 2240 Arbitrage(最短路 套汇)
题意 给你n种币种之间的汇率关系 推断是否能形成套汇现象 即某币种多次换为其他币种再换回来结果比原来多 基础的最短路 仅仅是加号换为了乘号 #include<cstdio> #in ...
- 最短路(Floyd_Warshall) POJ 2240 Arbitrage
题目传送门 /* 最短路:Floyd模板题 只要把+改为*就ok了,热闹后判断d[i][i]是否大于1 文件输入的ONLINE_JUDGE少写了个_,WA了N遍:) */ #include <c ...
- poj 2240 Arbitrage 题解
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21300 Accepted: 9079 Descri ...
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- poj 2240 Arbitrage (Floyd)
链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...
- POJ 2240 Arbitrage【Bellman_ford坑】
链接: http://poj.org/problem?id=2240 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- poj 2240 Arbitrage(Bellman_ford变形)
题目链接:http://poj.org/problem?id=2240 题目就是要通过还钱涨自己的本钱最后还能换回到自己原来的钱种. 就是判一下有没有负环那么就直接用bellman_ford来判断有没 ...
- POJ 2240 - Arbitrage(bellman_ford & floyd)
题意: 给出一些货币和货币之间的兑换比率,问是否可以使某种货币经过一些列兑换之后,货币值增加. 举例说就是1美元经过一些兑换之后,超过1美元.可以输出Yes,否则输出No. 分析: 首先我们要把货币之 ...
- POJ 2240 - Arbitrage - [bellman-ford求最短路]
Time Limit: 1000MS Memory Limit: 65536K Description Arbitrage is the use of discrepancies in currenc ...
随机推荐
- Div 内部所有元素 全部垂直对齐
http://stackoverflow.com/questions/7273338/how-to-vertically-align-an-image-inside-div How it works: ...
- Node.Js之【Stream 之复制文件问题】
var fs = require('fs'), path = require('path'), out = process.stdout; var filePath = 'F:/IMG_0221.MO ...
- xampp下安装yii框架下遇到的问题
用yii框架来生成web目录是输入E:\xampp\htdocs\yii\framework/yiic webapp E:\xampp\htdocs\web 时提示php不是内部命令,也不是... 这 ...
- Matlab生成动态链接库供C#调用
1.首先在Matlab中编写一个或几个.m文件 2.然后在命令空间中输入命令:deploytool 3.修改工程名称,修改需要生成文件后缀 4.添加类,添加文件,然后点击生成.
- iOS 基础 第四天(0809)
0809 - 内存管理,只对oc对象生效. alloc.retain.release.retainCount 局部变量是放在栈里面的,oc对象是放在堆里面的.栈里面的内容系统自动回收,而堆里面的内容还 ...
- 自定义UICollectionViewLayout并添加UIDynamic - scorpiozj(转)
转载自:http://www.tuicool.com/articles/jM77Vf 自定义UICollectionViewLayout并添加UIDynamic UICollectionVie ...
- [Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)(转)
转载自:http://blog.csdn.net/onlyou930/article/details/9299169 分类: Objective-C2013-07-11 11:54 3420人阅读 评 ...
- 用于软件包管理的21个Linux YUM命令
FROM:http://os.51cto.com/art/201309/411895.htm YUM(Yellowdog Updater Modified)是一款开源命令行及图形化软件包管理工具,面向 ...
- C#和Js 编码和解码方法
Server.UrlDecode(); Server.UrlEncode(); Server.HtmlDecode(); Server.HtmlEncode();
- apache与nginx日志文件的区别(转载)
apache与nginx日志文件的区别 转载:http://www.xfcodes.com/apache/log/3270.htm 导读:apache与nginx日志文件的区别,在apache与ngi ...