两种货币的交换可以当成两条边,建图后跑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. Dockerfile centos7_php5.6.36

    Dockerfile: FROM centos:7 MAINTAINER www.ctnrs.com RUN yum install epel-release -y && \ yum ...

  2. Full Regularization Path for Sparse Principal Component Analysis

    目录 背景 Notation Sparse PCA Semidefinite Relaxation Low Rank Optimization Sorting and Thresholding 背景 ...

  3. python中map()函数用法

    map函数的原型是map(function, iterable, …),它的返回结果是一个列表. 参数function传的是一个函数名,可以是python内置的,也可以是自定义的. 参数iterabl ...

  4. Ajax中文乱码的解决

    网上有很多解决Ajax中文乱码的例子,昨晚弄了很久,最终确定一种“确实”有效地方法.首先我有必要说明一下我遇到的情况:有一个注册页面,注册用户填完信息并提交后,页面获得信息并通过java servle ...

  5. Servlet处理GET和POST请求

    doGet() . doPost().service()方法 doGet()表示,当客户端是使用get方式请求该servlet时,那么就会触发执行doGet()方法中的代码. doPost()表示,当 ...

  6. Linux系统mysql使用(二)

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

  7. react 组件列表

    let data=[ [ '同时入选IMDB250和豆瓣电影250的电影', '带你进入不正常的世界', '用电[影]来祭奠逝去的岁月', '女孩们的故事[电影]', '', '使用 App [找电影 ...

  8. SQL常见问题积累

    SQL积累--仅适用于SQL Server 1.sql中,字符串保存序号,按照数字顺序进行排序 ))),) asc --householdNo 为要排序字段 2.控制小数位数 ,),,)))+'%' ...

  9. vue 动态插入组件

    HTML代码: <div id="app"> <p>{{ message }}</p> <button @click="add( ...

  10. j收集ava面试题

    史上最全Java面试题(带全部答案) https://blog.csdn.net/linzhiqiang0316/article/details/80473906