套汇问题,从源点做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. Win10系统64位快速专业安装版 V2016年

    win10系统64位快速专业安装版 V2016年2月 系统下载:http://www.xitongma.com/ Ghost Win10 64位正式装机专业版2016 微软向Windows用户推送了w ...

  2. Slacklining 2017/2/6

    原文 Get ready for a different kind of challenge What happens when mountain climbers take a day off?Ap ...

  3. 在SQL SERVER 2005中还原数据库时出现错误:system.data.sqlclient.sqlerror 媒体集有 2 个媒体簇 但只提供了 1 个。必须提供所有成员。 (microsoft.sqlserver.smo)

    问题:在SQL SERVER 2005中还原数据库时出现错误:system.data.sqlclient.sqlerror 媒体集有 2 个媒体簇 但只提供了 1 个.必须提供所有成员. (micro ...

  4. strong 、weak、copy 、assign 、retain 、unsafe_unretained 与autoreleasing区别和作用

    strong关键字与retain关似,用了它,引用计数自动+1,用实例更能说明一切 @property (nonatomic, strong) NSString *stringA; @property ...

  5. 四、绘图可视化之Seaborn

    Seaborn-Powerful Matplotlib Extension seaborn实现直方图和密度图 import numpy as np import pandas as pd import ...

  6. end和sep的使用方法

    end: 默认是换行'\n',表示以什么结尾,比如以, | \n 等 方法: 默认end = '\n' a b c 如果end = ' ' a b c sep: 默认是空格' ' 表示两个字符之间用什 ...

  7. 移动网页端HTML5 meta便签

    width = device-width:标识宽度是设备屏幕的宽度 initial-scale = 1.0 :标识初始的缩放比例 minimum-scale =0.5 :表示最小的缩放比例 maxim ...

  8. VUE +element el-table运用sortable 拖拽table排序,实现行排序,列排序

    Sortable.js是一款轻量级的拖放排序列表的js插件(虽然体积小,但是功能很强大) 项目需求是要求能对element中 的table进行拖拽行排序 这里用到了sorttable Sortable ...

  9. path.join()与path.resolve()区别

    1.path.resolve([...paths]) path.resolve() 方法会把一个路径或路径片段的序列解析为一个绝对路径. 给定的路径的序列是从右往左被处理的,后面每个 path 被依次 ...

  10. MFC编辑框换行

    字符串结尾加上"\r\n": 编辑框属性设置:Auto HScroll为False,Multiline为True,Want Return为True. =============== ...