题目链接:http://poj.org/problem?id=1860

Description

Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations only with these currencies. There can be several points specializing in the same pair of currencies. Each point has its own exchange rates, exchange rate of A to B is the quantity of B you get for 1A. Also each exchange point has some commission, the sum you have to pay for your exchange operation. Commission is always collected in source currency.
For example, if you want to exchange 100 US Dollars into Russian
Rubles at the exchange point, where the exchange rate is 29.75, and the
commission is 0.39 you will get (100 - 0.39) * 29.75 = 2963.3975RUR.

You surely know that there are N different currencies you can deal
with in our city. Let us assign unique integer number from 1 to N to
each currency. Then each exchange point can be described with 6 numbers:
integer A and B - numbers of currencies it exchanges, and real RAB, CAB, RBA and CBA - exchange rates and commissions when exchanging A to B and B to A respectively.

Nick has some money in currency S and wonders if he can somehow,
after some exchange operations, increase his capital. Of course, he
wants to have his money in currency S in the end. Help him to answer
this difficult question. Nick must always have non-negative sum of money
while making his operations.

Input

The
first line of the input contains four numbers: N - the number of
currencies, M - the number of exchange points, S - the number of
currency Nick has and V - the quantity of currency units he has. The
following M lines contain 6 numbers each - the description of the
corresponding exchange point - in specified above order. Numbers are
separated by one or more spaces. 1<=S<=N<=100, 1<=M<=100,
V is real number, 0<=V<=103.

For each point exchange rates and commissions are real, given with at most two digits after the decimal point, 10-2<=rate<=102, 0<=commission<=102.

Let us call some sequence of the exchange operations simple if no
exchange point is used more than once in this sequence. You may assume
that ratio of the numeric values of the sums at the end and at the
beginning of any simple sequence of the exchange operations will be less
than 104.

Output

If Nick can increase his wealth, output YES, in other case output NO to the output file.

Sample Input

3 2 1 20.0
1 2 1.00 1.00 1.00 1.00
2 3 1.10 1.00 1.10 1.00

Sample Output

YES

题目大意:有若干种货币,部分可以互相兑换,兑换时满足题目所给公式。现告诉你有几种货币,几种兑换方式,以及Nick所拥有的货币种类及其金额,问你能否通过若干次兑换后,兑回当前货币且金额增加,兑换过程中不能出现负值
解题思路:Bellman_Ford的变种,只需要将判负环的条件改为判正环即可,在进行松弛操作时,由于不能出现负值,将初始权值赋为0
 #include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map> using namespace std; typedef struct Edge{
int beg, end;
double r, c;
}Edge; int n, m, s, edges;
double v, dis[];
Edge edge[]; void setedge( int beg, int end, double r, double c ){
edges++;
edge[edges].beg = beg;
edge[edges].end = end;
edge[edges].r = r;
edge[edges].c = c;
} bool relax( int beg, int end, double r, double c ){
if( ( dis[beg] - c ) * r > dis[end] ){
dis[end] = ( dis[beg] - c ) * r;
return true;
}
return false;
} bool Bellman_Ford(){
for( int t = ; t < n; t++ ){
for( int i = ; i <= edges; i++ ){
relax( edge[i].beg, edge[i].end, edge[i].r, edge[i].c );
}
} for( int i = ; i <= edges; i++ ){
if( relax( edge[i].beg, edge[i].end, edge[i].r, edge[i].c ) )
return false;
} return true;
} int main(){
ios::sync_with_stdio( false ); while( cin >> n >> m >> s >> v ){
edges = ;
int beg, end;
double r1, c1, r2, c2;
while( m-- ){
cin >> beg >> end >> r1 >> c1 >> r2 >> c2;
setedge( beg, end, r1, c1 );
setedge( end, beg, r2, c2 );
}
memset( dis, , sizeof( dis ) );
dis[s] = v;
if( Bellman_Ford() )
cout << "NO" << endl;
else cout << "YES" << endl;
} return ;
}

												

POJ-1860 Currency Exchange( Bellman_Ford, 正环 )的更多相关文章

  1. 最短路(Bellman_Ford) POJ 1860 Currency Exchange

    题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...

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

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

  3. POJ 1860 Currency Exchange 最短路+负环

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

  4. POJ 1860 Currency Exchange + 2240 Arbitrage + 3259 Wormholes 解题报告

    三道题都是考察最短路算法的判环.其中1860和2240判断正环,3259判断负环. 难度都不大,可以使用Bellman-ford算法,或者SPFA算法.也有用弗洛伊德算法的,笔者还不会SF-_-…… ...

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

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

  6. poj - 1860 Currency Exchange Bellman-Ford 判断正环

    Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你 ...

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

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

  8. POJ 1860 Currency Exchange(如何Bellman-Ford算法判断图中是否存在正环)

    题目链接: https://cn.vjudge.net/problem/POJ-1860 Several currency exchange points are working in our cit ...

  9. Currency Exchange POJ - 1860 (spfa判断正环)

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

随机推荐

  1. 配置多个JDK存在的问题与解决方案 (亲测可用)

    安装多个JDK时的技巧 (亲测可用) 我的电脑本来是JDK8的,后来的想在不同的JDK版本下测试JDK的垃圾回收器. 一开始的的思路是,先安装JDK,为每个JDK配置自己的家目录,然后在想用哪个版本的 ...

  2. python中的赋值操作与C语言中的赋值操作中的巨大差别

    首先让我们来看一个简单的C程序: a = ; b = a; b = ; printf("a = %d, b = %d\n", a, b); 相信只要学过C语言, 不用运行程序便能知 ...

  3. Appium+python自动化(二十七)-让你在手机找到溜冰一样的感觉666,溜得飞起来 - 低级滑动(超详解)

    简介 随着现在智能手机的普及和应用,小到五六岁或者更小的娃娃,老至七八十岁老头老太太都是智能手机的用户,基本上达到每个人都在用,每次在地铁或者公交上,就看看到这样的场面,手指不停地在手机屏幕上来来回回 ...

  4. Drawable 使用详解

    极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android Drawable 是Android 中图像显示的常用方法. 概念:Drawable ...

  5. JVM总结(三)

    JVM总结(3)Class文件,类加载机制.编译过程 Java编译器先把Java代码编译为存储字节码的Class文件,再通过Class文件进行类加载. Class类文件的结构 Java编译器可以把Ja ...

  6. red hat enterprise Linux 64 bit 配置IP

    在win7 64位操作系统的台式机器上,安装了VMware® Workstation,9.0.1 build-894247.新建一个虚拟机安装linux.具体过程请搜索相关文档.安装的时候选择的网络连 ...

  7. JavaWeb——使用会话维持状态2

    在这次的例子里面,将完成一类似购物车的功能,在客户访问网站的时候,会选中自己将要购买的商品,而购物车将始终维持着商品的状态,会话将联系起选择第一个商品(第一个请求),选择其他商品(其他请求)以及付款等 ...

  8. 使用mybatis实现分页查询示例代码分析

    *******************************************分页查询开始*************************************************** ...

  9. vue过滤器微信小程序过滤器和百度智能小程序过滤器

    因为最近写了微信小程序和百度小程序,用到了过滤器,感觉还挺好用的,所以就来总结一下,希望能帮到你们. 1. 微信小程序过滤器: 1.1:首先建一个单独的wxs后缀的文件,一般放在utils文件夹里面. ...

  10. 【Aizu - 2249】Road Construction(最短路 Dijkstra算法)

    Road Construction Descriptions Mercer国王是ACM王国的王者.他的王国里有一个首都和一些城市.令人惊讶的是,现在王国没有道路.最近,他计划在首都和城市之间修建道路, ...