Currency Exchange

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

Appoint description: 
System Crawler  (2015-05-14)

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 R AB, CAB, R BA and C BA - 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<=10 3
For each point exchange rates and commissions are real, given with at most two digits after the decimal point, 10 -2<=rate<=10 2, 0<=commission<=10 2
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 10 4

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

松弛方法变反,最后检查是否有正环。
 #include <iostream>
#include <cstdio>
using namespace std; int N,M,S;
double V;
double D[];
struct Node
{
int from,to;
double r,c;
}G[]; bool Bellman_Ford(void);
int main(void)
{
int from,to;
double box; while(scanf("%d%d%d%lf",&N,&M,&S,&V) != EOF)
{
for(int i = ;i < M * ;)
{
scanf("%d%d%lf%lf",&G[i].from,&G[i].to,&G[i].r,&G[i].c);
i ++;
G[i].from = G[i - ].to;
G[i].to = G[i - ].from;
scanf("%lf%lf",&G[i].r,&G[i].c);
i ++;
}
if(Bellman_Ford())
puts("YES");
else
puts("NO");
}
} bool Bellman_Ford(void)
{
bool update;
fill(D,D + ,);
D[S] = V; for(int i = ;i < N - ;i ++)
{
update = false;
for(int j = ;j < M * ;j ++)
if(D[G[j].to] < (D[G[j].from] - G[j].c) * G[j].r && (D[G[j].from] - G[j].c) * G[j].r >= )
{
update = true;
D[G[j].to] = (D[G[j].from] - G[j].c) * G[j].r;
if(D[S] > V)
return true;
}
if(!update)
break;
}
for(int i = ;i < M * ;i ++)
if(D[G[i].to] < (D[G[i].from] - G[i].c) * G[i].r)
return true;
return false;
}

POJ 1860 Currency Exchange (最短路)的更多相关文章

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

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

  2. poj 1860 Currency Exchange (最短路bellman_ford思想找正权环 最长路)

    感觉最短路好神奇呀,刚开始我都 没想到用最短路 题目:http://poj.org/problem?id=1860 题意:有多种从a到b的汇率,在你汇钱的过程中还需要支付手续费,那么你所得的钱是 mo ...

  3. POJ 1860 Currency Exchange 最短路 难度:0

    http://poj.org/problem?id=1860 #include <cstdio> //#include <queue> //#include <deque ...

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

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

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

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

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

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

  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 (最短路)

    Currency Exchange Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other) T ...

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

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

随机推荐

  1. 【汉字乱码】IE下GET形式传递汉字。

    js:encodeURI(); php:urlencode(); 举例: 本来打算这样使用 <a href="list.php?plate=辖区动态" charset=&qu ...

  2. C#实现Combobox自动匹配字符

    不多说了,如图,应客户要求,下拉框中需要自动匹配字符,可能有些人一早就对此很熟,但相对于我还是首次使用,还是花了一点时间,现记录下来,也希望能帮助大家更好的理解. 首先要设定Combobox的Drop ...

  3. 手机web开发Repeater四层嵌套

    最近有朋友想让我给他做个手机上页面,页面功能是显示省--市--区--门店信息,这种层级关系的数据,首先来看看效果: 我想现在的手机都是智能机了对于普通的asp.net页面开发应该没什么两样,不过最终开 ...

  4. C++的优秀特性4:指针

    (转载请注明原创于潘多拉盒子) 其实指针不是C++的特性,而是地地道道的C的特性.有人说C++继承了C的指针,实在是败笔,造成内存泄漏云云,纯粹是不懂.可以这么说,如果没有指针,C++会逊色很多,应用 ...

  5. EWARM STM32 向量表偏移设置

    system_stm32f2xx.c #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table ...

  6. Animated Scroll to Top

    Due to a number of requests, I'm writing a detail tutorial on how to create an animated scroll to to ...

  7. wpa_supplicant 连接成功后,如何配置wlan0与br0 协调上网

    wlan0 地址,路由配置完成后,加入两条iptables 规则. #iptables -A FORWARD -i wlan0 -o br0 -s -m state --state NEW -j AC ...

  8. Java学习笔记之深入理解引用

    引言:Java中数据传递的方式,除了基本数据类型是按照值传递,其它类型全部是按照引用传递,这和C++有很大区别,但是很多网上文章都解释的不清楚,甚至是错误的,在查阅资料之后,下面整理出一个比较容易理解 ...

  9. shader 语言 【转】

    shader语言 3dlabs改名后其开发者网站关闭 可以在这里下载shadergen http://3dshaders.com/home/index.php?option=com_weblinks& ...

  10. MySQL数据库最大连接数

    MYSQL数据库安装完毕后,默认最大连接数是100. 命令: show processlist; 假设是root帐号,你能看到全部用户的当前连接.假设是其他普通帐号,仅仅能看到自己占用的连接. sho ...