两种货币的交换可以当成两条边,建图后跑Bellman_ford算法就好了。

Bellman_ford算法可以用来处理负边权,所以可以判断是否存在负环。反过来就可以判断是否存在正环。

 /*--------------------------------------------------------------------------------------*/
// Helica's header
// Second Edition
// 2015.11.7
//
#include <algorithm>
#include <iostream>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> //debug function for a N*M array
#define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++)\
{for(int j=;j<(M);j++){\
printf("%d",G[i][j]);}printf("\n");}
//debug function for int,float,double,etc.
#define debug_var(X) cout<<#X"="<<X<<endl;
/*--------------------------------------------------------------------------------------*/
using namespace std; const int maxn = +;
int N,M,T,S;
int tol;
double V; struct Edge
{
int u,v;
double c,r;
}E[*maxn]; double dist[maxn]; bool bellman_ford(int start,int n)
{
memset(dist,,sizeof dist);
dist[start] = V; for(int i=;i<n;i++)
{
bool flag = false;
for(int j=;j<tol;j++)if(dist[E[j].v] < (dist[E[j].u]-E[j].c)*E[j].r )
{
dist[E[j].v] = (dist[E[j].u]-E[j].c)*E[j].r;
flag = true;
}
if(!flag) return false;
} for(int j=;j<tol;j++)
{
if(dist[E[j].v] < (dist[E[j].u]-E[j].c)*E[j].r)
return true;
}
return false;
} int main()
{
while(~scanf("%d%d%d%lf",&N,&M,&S,&V))
{
int a,b;
double r1,r2,c1,c2;
tol = ;
for(int i=;i<M;i++)
{
scanf("%d%d%lf%lf%lf%lf",&a,&b,&r1,&c1,&r2,&c2);
E[tol].u = a;E[tol].v = b;
E[tol].c = c1;E[tol++].r = r1;
E[tol].u = b;E[tol].v = a;
E[tol].c = c2;E[tol++].r = r2;
}
if(bellman_ford(S,N))
printf("YES\n");
else
printf("NO\n"); }
}

POJ1860-Currency Exchange-判正环的更多相关文章

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

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

  2. poj1860(spfa判正环)

    题目连接:http://poj.org/problem?id=1860 题意:有多种从a到b的汇率,在你汇钱的过程中还需要支付手续费,那么你所得的钱是 money=(nowmoney-手续费)*rat ...

  3. POJ-1860 Currency Exchange---Bellman-Ford判断正环

    题目链接: https://vjudge.net/problem/POJ-1860 题目大意: 我们的城市有几个货币兑换点.让我们假设每一个点都只能兑换专门的两种货币.可以有几个点,专门从事相同货币兑 ...

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

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

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

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

  6. POJ1860 Currency Exchange —— spfa求正环

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

  7. poj1860 Currency Exchange(spfa判断是否存在正环)

    题意:有m个货币交换点,每个点只能有两种货币的互相交换,且要给佣金,给定一开始的货币类型和货币数量,问若干次交换后能否让钱增加. 思路:spfa求最长路,判断是否存在正环,如果存在则钱可以在环中一直增 ...

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

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

  9. POJ 2240 Arbitrage (Bellman Ford判正环)

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:27167   Accepted: 11440 Descri ...

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

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

随机推荐

  1. Django 的路由层 视图层 模板层

    --------------------------------------------------------------通过苦难,走向欢乐.——贝多芬 Django-2的路由层(URLconf) ...

  2. Leetcode 143. Reorder List(Medium)

    Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do thi ...

  3. Python并发编程

    进程 相关概念 进程 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础.在早期面向进程设计的计算机结构中,进程是程序的基本 ...

  4. fileInput插件上传文件

    一.ftl <form action="" method="post" name="form" id="form" ...

  5. MySQL的视图总结

    使用下面格式创建视图: create or replace view viewName as select ..... from ...... where .... 删除视图: drop view v ...

  6. 【学习总结】GirlsInAI ML-diary day-6-String字符串

    [学习总结]GirlsInAI ML-diary 总 原博github链接-day6 认识字符串 字符串的性质 字符串的玩法 1-字符串就是字符的序列 序列,代表字符串是有顺序的!这里很重要. 比如我 ...

  7. Linux系统mysql使用(二)

    一.查看某数据库的表 # 假设此时数据库名为hiveuse hive; show tables;

  8. 给网站配置免费的HTTS证书

    取经自思否:https://segmentfault.com/a/1190000015231137 https 的网站 搜索引擎 会优先收录,所以就抽时间记录下配置博客的过程,各种找资料,终于给我找到 ...

  9. [转帖]Windows批处理(cmd/bat)常用命令小结

    Windows批处理(cmd/bat)常用命令小结 非常值得学习的文档 先放这里 有时间做实验, 转载自:“趣IT”微信公共号 前言 批处理文件(batch file)包含一系列 DOS命令,通常用于 ...

  10. Oracle创建及调用存储过程