套汇问题,从源点做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. 使用POI创建word表格-在表格单元格中创建子表格

    要实现的功能如下:表格中的单元格中有子表格 实现代码如下: XWPFParagraph cellPara = row.getCell(j).getParagraphArray(0); //row.ge ...

  2. Objective-C Runtime Reference

    This document describes the OS X Objective-C 2.0 runtime library support functions and data structur ...

  3. vue+element ui项目总结点(三)富文本编辑器 vue-wangeditor

    1.参考 https://www.npmjs.com/package/vue-wangeditor 使用该富文本编辑器 <template> <div class="egi ...

  4. shell 复合条件测试 if [ $1 == "1" -o $1 == "0" ] ------==和-eq怎么用

    想要实现: ”,或者$1等于“” ];then 输出一些东西 ”,或者$1等于“” ];then 输出一些东西 fi 这里比较难操作的是等于和或者: 等于: -eq  或者 == 或者: -o 见: ...

  5. java导入Excel表格数据

    首先导入Excel数据需要几样东西 第一需要两个依赖包,这里直接是在pom注入依赖 <!--excel--> <dependency> <groupId>org.a ...

  6. hibernate的注解

    1.many-to-one @ManyToOne @JoinColumn(name = "user_id") 2.many-to-many /** * 双向关联关系中,有且仅有一端 ...

  7. Bootstrap历练实例:表单控件大小

    表单控件大小 您可以分别使用 class .input-lg 和 .col-lg-* 来设置表单的高度和宽度. 实例: <!DOCTYPE html><html><hea ...

  8. 寄存器变量 extern 外部变量 外部函数

    寄存器变量 这个可以不理睬 register 关键字定义的变量直接放在寄存器当中 寄存器是放在CPU内部的存储单元,它的速度比内存快的多,所以当程序中有10000多次调用同一个变量的时候声明成寄存器变 ...

  9. 初涉树形dp

    算是一个……复习以及进阶? 什么是树形dp 树形dp是一种奇妙的dp…… 它的一个重要拓展是和各种树形的数据结构结合,比如说在trie上.自动机上的dp. 而且有些时候还可以拓展到环加外向树.仙人掌上 ...

  10. MySql压缩版安装及避免1055错误和msvcp120.dll丢失

    MySql压缩版安装及避免1055错误和msvcp120.dll丢失 MySQL压缩版的安装快速方便,5.7及最新的8版本安装方式大致相同. 在使用group by分组时,可能会遇到1055错误. 另 ...