Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 22111   Accepted: 7986

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
这题使用Bellman-Ford算法,将判断条件修改一下即可,找到是否有权增加的回路
 #include <iostream>
#include<string.h>
using namespace std;
struct exch {
int src, des;
float rate, commission;
} ex[];
int main() {
int cur_num, exp_num, cur;
float init;
float c[];
while (cin >> cur_num >> exp_num >> cur >> init) {
memset(c, , * sizeof(float));
c[cur] = init;
for (int i = ; i < exp_num; i++) {
int a, b;
cin >> a >> b;
ex[ * i].src = a;
ex[ * i].des = b;
cin >> ex[ * i].rate >> ex[ * i].commission;
ex[ * i + ].src = b;
ex[ * i + ].des = a;
cin >> ex[ * i + ].rate >> ex[ * i + ].commission;
}
for (int i = ; i < cur_num ; i++) {
for (int j = ; j < * exp_num; j++) {
if (c[ex[j].des]
< (c[ex[j].src] - ex[j].commission) * ex[j].rate) {
c[ex[j].des] = (c[ex[j].src] - ex[j].commission)
* ex[j].rate;
}
}
}
int flag = ;
for (int j = ; j < * exp_num; j++) {
if (c[ex[j].des] < (c[ex[j].src] - ex[j].commission) * ex[j].rate) {
flag=;
break;
}
}
if(flag==){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
} }
return ; }

Currency Exchange - poj 1860的更多相关文章

  1. (最短路 SPFA)Currency Exchange -- poj -- 1860

    链接: http://poj.org/problem?id=1860 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 2326 ...

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

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

  3. Currency Exchange POJ - 1860 (spfa)

    题目链接:Currency Exchange 题意: 钱的种类为N,M条命令,拥有种类为S这类钱的数目为V,命令为将a换成b,剩下的四个数为a对b的汇率和a换成b的税,b对a的汇率和b换成a的税,公式 ...

  4. kuangbin专题专题四 Currency Exchange POJ - 1860

    题目链接:https://vjudge.net/problem/POJ-1860 大致题意:有不同的货币,有很多货币交换点,每个货币交换点只能两种货币相互交换,有佣金C,汇率R. 每次交换算一次操作, ...

  5. Currency Exchange POJ - 1860 spfa判断正环

    //spfa 判断正环 #include<iostream> #include<queue> #include<cstring> using namespace s ...

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

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

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

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

  8. POJ 1860 Currency Exchange (最短路)

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

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

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

随机推荐

  1. HDU 4034 Graph Floyd最短路

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4034 题意: 给你一个最短路的表,让你还原整个图,并使得边最少 题解: 这样想..这个表示通过floy ...

  2. Walls and Gates -- LeetCode

    You are given a m x n 2D grid initialized with these three possible values. -1 - A wall or an obstac ...

  3. ssh框架整合shiro权限

    关于整合shiro,首先在ssh整合的基础上进行组合 1.首先,要导入几个依赖(整合ssh与shiro的依赖): <properties><shiro.version>1.3. ...

  4. (转)Unity3D研究院之游戏架构脚本该如何来写(三十九)

     这篇文章MOMO主要想大家说明一下我在Unity3D游戏开发中是如何写游戏脚本的,对于Unity3D这套游戏引擎来说入门极快,可是要想做好却非常的难.这篇文章的目的是让哪些已经上手Unity3D游戏 ...

  5. Flash 3D学习计划

    1.理解并记住3D渲染的一般管线流程(一天). 2.理解世界,取景,投影变换,并理解投影坐标系(一天). 3.学习VB,IB相关,理解三角形顶点顺序:在屏幕上显示2D矩形,并实现缩放,平移,旋转(三天 ...

  6. MySQL类型转换 使用CAST将varchar转换成int类型排序

    --使用CAST将varchar转换成int类型排序 select distinct(zone_id) from guild_rank_info order by CAST(zone_id as SI ...

  7. [读书笔记] CSS揭秘-背景与边框

    半透明边框 默认情况下,背景会延伸到边框所在的区域下层.可以通过background-clip属性调整该默认行为. border: 10px solid rgba(0,0,0,.2) backgrou ...

  8. JavaScript传递变量:值传递?引用传递?

    今天在看 seajs-2.2.1/src/util-events.js源码,里面有段代码不是很理解: var events = data.events = {} // Bind event seajs ...

  9. 查找文件命令find总结以及查找大文件

    find / -name *** 示例如下: [dinpay@zk-spark-01 spark]$ find /home/ll -name slaves /home/ll/spark/conf/sl ...

  10. PHP使用mysqli连接MySQL数据库

    使用mysqli函数库连接MySQL,支持面向对象和面向过程两种方式: 1.面向对象的使用方式 建立一个连接 $db = new mysqli('localhost', 'root', '123456 ...