[poj1860] Currency Exchange (bellman-ford算法)
题目链接:http://poj.org/problem?id=1860
题目大意:给你一些兑换方式,问你能否通过换钱来赚钱?
使用ford算法,当出现赚钱的时候就返回YES,如果不能赚钱,则返回NO
应该是可以停下来的,但是我不会分析复杂度,谁来教教我?
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <numeric>
#include <iterator>
#include <iostream>
#include <cstdlib>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ size()
#define ST begin()
#define ED end()
#define CLR clear()
#define ZERO(x) memset((x),0,sizeof(x))
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const double EPS = 1e-; struct EDGE{
int from,to;
double r,c;
EDGE(int _from = , int _to = , double _r = , double _c = ) :
from(_from),to(_to),r(_r),c(_c) {}
}; vector<EDGE> vec;
int N,M,S;
double V;
double d[]; bool floyd(int s){
d[s] = V;
bool flag = false;
while(true){
flag = false;
for(int i=;i<vec.SZ;i++){
const EDGE& e = vec[i];
if(d[e.from]>0.0 && d[e.to]<(d[e.from]-e.c)*e.r){
d[e.to]=(d[e.from]-e.c)*e.r;
flag = true;
}
}
if(d[s]>V) return true;
if(!flag) {
break;
}
}
return d[s]>V;
} int main(){
while(EOF!=scanf("%d%d%d%lf",&N,&M,&S,&V)){
vec.CLR;
ZERO(d);
int from,to;
double rab,cab,rba,cba;
for(int i=;i<M;i++){
scanf("%d%d%lf%lf%lf%lf",&from,&to,&rab,&cab,&rba,&cba);
vec.PB(EDGE(from,to,rab,cab));
vec.PB(EDGE(to,from,rba,cba));
}
puts(floyd(S)?"YES":"NO");
}
return ;
}
[poj1860] Currency Exchange (bellman-ford算法)的更多相关文章
- Bellman—Ford算法思想
---恢复内容开始--- Bellman—Ford算法能在更普遍的情况下(存在负权边)解决单源点最短路径问题.对于给定的带权(有向或无向)图G=(V,E),其源点为s,加权函数w是边集E的映射.对图G ...
- Bellman - Ford 算法解决最短路径问题
Bellman - Ford 算法: 一:基本算法 对于单源最短路径问题,上一篇文章中介绍了 Dijkstra 算法,但是由于 Dijkstra 算法局限于解决非负权的最短路径问题,对于带负权的图就力 ...
- POJ1860——Currency Exchange(BellmanFord算法求最短路)
Currency Exchange DescriptionSeveral currency exchange points are working in our city. Let us suppos ...
- POJ1860:Currency Exchange(BF)
http://poj.org/problem?id=1860 Description Several currency exchange points are working in our city. ...
- POJ1860 Currency Exchange(bellman-ford)
链接:http://poj.org/problem?id=1860 Currency Exchange Description Several currency exchange points are ...
- POJ1860 Currency Exchange【最短路-判断环】
Several currency exchange points are working in our city. Let us suppose that each point specializes ...
- poj1860 Currency Exchange(spfa判断正环)
Description Several currency exchange points are working in our city. Let us suppose that each point ...
- POJ1860 Currency Exchange —— spfa求正环
题目链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Tota ...
- POJ-1860 Currency Exchange( Bellman_Ford, 正环 )
题目链接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...
随机推荐
- win7(64)位下WinDbg64调试VMware10下的win7(32位)
win7(64)位下WinDbg64调试VMware10下的win7(32位) 一 Windbg32位还是64位的选择 参考文档<Windbg 32位版本和64位版本的选择> http:/ ...
- 如何重新安装DEDECMS织梦系统
重装的方法: 1.找到安装目录\install\index.php.bak文件,改名为index.php: 2.删除安装目录\install\install_lock文件:
- C#获取字符首字母
///<summary> /// 获取字符首字母 /// </summary> public static string GetPyChar(string c) { if (s ...
- 2014年5月份第3周51Aspx源码发布详情
HGM简单连连看游戏源码 2014-5-19 [VS2010]源码描述:这是一款基于WinForm窗体程序的简单水果连连看的小游戏.界面比较美观, 功能如下:该游戏可以显示当前关卡,还有剩余时间.重 ...
- 2016 - 1- 23 iOS中xml解析 (!!!!!!!有坑要解决!!!!!!)
一: iOS中xml解析的几种方式简介 1.官方原生 NSXMLParser :SAX方式解析,使用起来比较简单 2.第三方框架 libxml2 :纯C 同时支持DOM与SAX GDataXML: D ...
- 在 Sublime Text 2 中使用 SFTP 插件快速编辑远程服务器文件
在 Sublime Text 2 中使用 SFTP 插件快速编辑远程服务器文件 开源程序 浏览:29555 2013年05月02日 文章目录[隐藏] 常见的工作流程 SFTP 安装和使用方法 第一步: ...
- Linux的awk命令
简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再 ...
- Spring框架学习(二)
一.依赖注入的三种注入方式 Spring框架为我们提供了三种注入方式:set注入.构造方法注入和接口注入. 1.set注入 规律:无论给什么赋值,配置文件中<property>标签的nam ...
- OD调试篇9
渐渐地要用比较高明一点的方法去破解软件了 那好,看看今天的程序先 先载入 测试下程序 发现这是一个未注册版本的程序,注册也不让注册,注册就跳出You have rntered an invalid ...
- Android 中pid与uid的作用与区别
PID:为Process Identifier, PID就是各进程的身份标识. 程序一运行系统就会自动分配给进程一个独一无二的PID.进程中止后PID被系统回收,可能会被继续分配给新运行的程序,但是在 ...