题目链接: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算法)的更多相关文章

  1. Bellman—Ford算法思想

    ---恢复内容开始--- Bellman—Ford算法能在更普遍的情况下(存在负权边)解决单源点最短路径问题.对于给定的带权(有向或无向)图G=(V,E),其源点为s,加权函数w是边集E的映射.对图G ...

  2. Bellman - Ford 算法解决最短路径问题

    Bellman - Ford 算法: 一:基本算法 对于单源最短路径问题,上一篇文章中介绍了 Dijkstra 算法,但是由于 Dijkstra 算法局限于解决非负权的最短路径问题,对于带负权的图就力 ...

  3. POJ1860——Currency Exchange(BellmanFord算法求最短路)

    Currency Exchange DescriptionSeveral currency exchange points are working in our city. Let us suppos ...

  4. POJ1860:Currency Exchange(BF)

    http://poj.org/problem?id=1860 Description Several currency exchange points are working in our city. ...

  5. POJ1860 Currency Exchange(bellman-ford)

    链接:http://poj.org/problem?id=1860 Currency Exchange Description Several currency exchange points are ...

  6. POJ1860 Currency Exchange【最短路-判断环】

    Several currency exchange points are working in our city. Let us suppose that each point specializes ...

  7. poj1860 Currency Exchange(spfa判断正环)

    Description Several currency exchange points are working in our city. Let us suppose that each point ...

  8. POJ1860 Currency Exchange —— spfa求正环

    题目链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Tota ...

  9. POJ-1860 Currency Exchange( Bellman_Ford, 正环 )

    题目链接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...

随机推荐

  1. 我的qq邮箱的GPG公钥

    呵呵,赶一波潮流,我的邮箱 175420840@qq.com 的GPG公钥如下,也可以在这里直接下载.具体可参见阮一峰的<GPG入门教程>. -----BEGIN PGP PUBLIC K ...

  2. 一台服务器发布多个tomcat并注册服务名办法

    修改服务名称 打开Tomcat7.0.65_1/bin/service.bat  修改注册服务名称 当然这个名字自己改 比如Tomcat7_2 原始文件:   set SERVICE_NAME=Tom ...

  3. blocked file type by sharepoint 分类: Sharepoint 2015-07-05 07:45 6人阅读 评论(0) 收藏

    o add or remove blocked file types by using Central Administration Verify that you have the followin ...

  4. Python的平凡之路(4)

    一.迭代器&生成器 生成器定义: 通过列表生成式,我们可以直接创建一个列表.但是,受到内存限制,列表容量肯定是有限的.而且,创建一个包含100万个元素的列表,不仅占用很大的存储空间,如果我们仅 ...

  5. 《C++primer》v5 第3章 字符串、向量和数组 读书笔记 习题答案

    本章问题 1.char *p="hello world";与char p[]="hello world"的问题. 简单说前者是一个指向字符串常量的指针,后者是一 ...

  6. Ztree使用笔记

    在项目中需要用到树,使用了Ztree.(官网地址:http://www.treejs.cn/v3/main.php#_zTreeInfo,介绍很详细,有API,有demo) 1.初始化树:   $.f ...

  7. TP验证

  8. MQTT实现长连接,IM最简单实例

    1,引入MqttSDK. 2, 头文件 #import "MQTTSession.h" //定义主题#define kTopic @"lichanghong"/ ...

  9. 1、c#对XML文件的解析

    1.XML文件 <?xml version="1.0" encoding="utf-8"?> <PersonF xmlns="&qu ...

  10. java类型转化之SimpleDateFormat-时间转化

    关于Date,时间戳(long),String类型之间的相互转换,主要是用到类SimpleDateFormat. 先介绍SimpleDateFormat类的一些常见格式: 1.参数: code des ...