[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 ...
随机推荐
- (BFS)uva2554-Snakes & Ladders
题目地址 不知道究竟是我的代码问题,还是oj出了问题(vjudge上看这道题全都是WA,没有AC的)就连直接用书上的代码都WA. 但还是先放出我这不确定正误的代码,大神路过如果有兴趣可以帮忙看一下. ...
- Install Java1.6
声明:一下内容主要来自网络,本来在此基础上根据自己的成功经验做了一些浅陋的(但有价值的)备注说明和修改. (本人也是ubuntu 11.10版本,但是是64位的,因此安装的java也是64位版本.) ...
- Linux(Ubuntu) 和 Python 常用命令
Linux: pwd: check current directory touch f1 f2 f3: create three empty files tree dir/: show the lev ...
- c# windows编程控件学习-1
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- android 面试总结,后续注意学习
1.数据结构和算法 一般情况下,工作中是用不到的,但是就是问,每个公司都问,而且有的公司还问的特别深,还让你手写代码.我觉得这个确实有点恶心,我个人也是很讨厌算法的,但是真是没办法,人家就问,你说怎么 ...
- Java语言概述
1.1 基础知识 ·第一代语言 打孔机--纯机器语言 ·第二代语言 汇编 ·第三代语言 C.Pascal.Fortran面向过程的语言 C++面向过程/面向对象 Java跨平台的纯面向对象的语言 .N ...
- 搭建Tomcat6源代码阅读环境
目标:使用MyEclipse8.5阅读Tomcat6源码. 第一步:在MyEclipse8.5中集成SVN插件. 第二步:从地址http://svn.apache.org/repos/asf/tomc ...
- linux系统下php安装mbstring扩展的二种方法
.执行 复制代码代码如下: yum install php-mbstring 2. 修改php.ini (这一步非常重要, 部分lxadmin版本无法自动修改) 复制代码代码如下: echo ‘ext ...
- php大力力 [042节] 今天做了一个删除功能
php大力力 [042节] 今天做了一个删除功能 if(isset($_GET['action'])){ if($_GET['action']=="del"){ $sql = &q ...
- Linux多人群聊系统(简单多线程服务器)
一:要求 1.通过一个服务器实现最多5个客户之间的信息群发. 2.服务器显示客户的登录与退出: 3.客户连接后首先发送客户名称,之后发送群聊信息: 4.客户输入bye代表退出,在线客户能显示其他客户的 ...