套汇问题,从源点做SPFA,如果有一个点入队次数大于v次(v表示点的个数)则图中存在负权回路,能够套汇,如果不存在负权回路,则判断下源点到自身的最长路是否大于自身,使用SPFA时松弛操作需要做调整

#include<iostream>

#include<cstdio>

#include<string.h>

#include <stdlib.h>

#include <math.h>

using namespace std;

const int maxn=2000;

double dist[maxn]={0},rate[maxn][maxn]={{0}},ope[maxn][maxn]={{0}},v;

int n,m,s,cnt[maxn]={0};

bool spfa(int scr)

{

int l=0,r=1,que[10000]={0},visit[maxn]={0},temp;

que[++l]=scr;

dist[scr]=v;

cnt[scr]=1;

while(l<=r)

{

temp=que[l++];

visit[temp]=0;

for(int i=1;i<=n;i++)

{

if (rate[temp][i]>0 &&dist[i]<(dist[temp]-ope[temp][i])*rate[temp][i])

{

dist[i]=(dist[temp]-ope[temp][i])*rate[temp][i];

if (visit[i]==0)

{

visit[i]=1;

que[++r]=i;

cnt[i]++;

if (cnt[i]>=n)returntrue;

}

}

}

}

return dist[s]>v;

}

int main()

{

int x,y;

scanf("%d%d%d%lf",&n,&m,&s,&v);

for(int i=1;i<=m;i++)

{

scanf("%d%d",&x,&y);

scanf("%lf%lf%lf%lf",&rate[x][y],&ope[x][y],&rate[y][x],&ope[y][x]);

}

if(spfa(s))printf("YES\n");else printf("NO\n");

return 0;

}

POJ 1860: Currency Exchange 【SPFA】的更多相关文章

  1. POJ 1860 Currency Exchange【SPFA判环】

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

  2. POJ 1860——Currency Exchange——————【最短路、SPFA判正环】

    Currency Exchange Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u S ...

  3. POJ 1860 Currency Exchange【bellman_ford判断是否有正环——基础入门】

    链接: http://poj.org/problem?id=1860 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  4. (简单) POJ 1860 Currency Exchange,SPFA判圈。

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

  5. poj 1860 Currency Exchange (SPFA、正权回路 bellman-ford)

    链接:poj 1860 题意:给定n中货币.以及它们之间的税率.A货币转化为B货币的公式为 B=(V-Cab)*Rab,当中V为A的货币量, 求货币S通过若干此转换,再转换为原本的货币时是否会添加 分 ...

  6. POJ 1860 Currency Exchange【bellman-Ford模板题】

    传送门:http://poj.org/problem?id=1860 题意:给出每两种货币之间交换的手续费和汇率,求出从当前货币s开始交换回到s,能否使本金增多. 思路:bellman-Ford模板题 ...

  7. POJ 1860 Currency Exchange(SPFA+邻接矩阵)

    ( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<cmath> #include<algori ...

  8. Poj 1860 Currency Exchange(Bellman-Ford,SPFA解单源最短路径问题)

    一.题意 有多个货币交易点,每个只能互换两种货币,兑换的汇率不同,并收取相应的手续费.有N种货币,假定你拥有第S中,数量为V,有M个兑换点.问你能不能通过兑换操作使你最后拥有的S币比起始的时候多. 二 ...

  9. POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)

    POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...

随机推荐

  1. Redis监控之redis-live.conf配置

    { "RedisServers": [ { "server": "192.168.1.201", "port": 637 ...

  2. maven打包错误:java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

    Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.118 sec <<< FAILURE! - in ...

  3. 如何删除github上项目的文件

    1. 你要有前面一章的开发平台和github插件,下面就是基于前面来做的. 如何删掉你github上的文件呢?想必你的电脑有一个下载的git工具了,如果还是没有的话,请用npm下载一个git.这是我已 ...

  4. 用python编写九九乘法表

    for i in range(1,10): for j in range(1,10): if j >i: print(end='') else: print(j,'*',i,'=',i*j,en ...

  5. python3中bytes、hex和字符串相互转换

    1.字符串转bytes a = 'abcd' a1 = bytes(a,encoding('utf-8')) 2.bytes转字符串 a = b'abcd' a1 = bytes.decode(a , ...

  6. Codeforces Round #274 (Div. 2)-C. Exams

    http://codeforces.com/contest/479/problem/C C. Exams time limit per test 1 second memory limit per t ...

  7. spring boot 下 dataTable|pagehelper 组合进行分页 筛选 排序

    1)Js 需提前引用 jquery.dataTables $(function () { //提示信息 初始化设置 一般不需要改 var lang = { "sProcessing" ...

  8. Hibernate中get()与load()的区别,以及关于ThreadLocal的使用方法

    一.get方法和load方法的简易理解 (1)get()方法直接返回实体类,如果查不到数据则返回null.load()会返回一个实体代理对象(当前这个对象可以自动转化为实体对象),但当代理对象被调用时 ...

  9. NSLocale

      1.创建本地化对象 // 根据本地标识符创建本地化对象 NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier"e ...

  10. Git学习之路

    目录 git安装 linux windows git命令 创建版本库 提交文件 仓库状态 版本回退 工作区和暂存区 工作区 暂存区 推送.下拉和克隆 推送 下拉 克隆 git应该可以说是程序员必备技能 ...