[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 ...
随机推荐
- 上下文菜单项(contextMenu)----长按按钮弹出菜单项
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- GIT(分布式版本控制系统)
Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目.[1] Git的读音为/gɪt/. Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本 ...
- ubuntu下firefox浏览器flash player插件的安装
自从装了双系统后,ubuntu下的音乐软件只能选择网页播放器了,这无疑是需要播放插件的,这个插件就是falsh player. 当初使用usb启动盘安装的,在安装的过程中还会报找不到CD-rom的错, ...
- 1、Android Bitmap详细介绍
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...
- HDU 4717 The Moving Points (三分法)
题意:给n个点的坐标的移动方向及速度,问在之后的时间的所有点的最大距离的最小值是多少. 思路:三分.两点距离是下凹函数,它们的max也是下凹函数.可以三分. #include<iostream& ...
- iOS 根据UIImage 修改UIImageView Frame (包括截取图片中间部分)
iOS UIImageView 根据需求调整frame 1.图片的宽和高不相等,截取图片的中间部分,截取的部分Size明确 2.图片的宽度要等于其父视图的类的宽度,然后根据宽度计算高度,保证 图片不变 ...
- React Native组件之Text
React Native组件之Text相当于iOS中的UILabel. 其基本属性如下: /** * Sample React Native App * https://github.com/face ...
- linux内核分析——扒开系统调用的三层皮
万子惠 + 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 实验部分 选择2 ...
- IP的包头格式什么?请分析每个字段的含义
Version:版本号 Header Length:IP包头长度 Type of service:服务类型 Total Length:IP包总长 Identifier:标识符 Flags:标记 Fra ...
- oracle 小知识
oracle: 数值随机的函数是 dbms_random.value(最大值,最小值) 用法是select dbms_random(3,0) from dual; oracle: 获取前100条 ...