Currency Exchange
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 21349   Accepted: 7653

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

Source

Northeastern Europe 2001, Northern Subregion
 #include<stdio.h>
struct edge
{
int u , v ;
double r , c ;
}e[];
int n , m , s ;
double cap ;
int cnt = ;
double d[] ; bool Bellman_ford()
{
for (int i = ; i <= n ; i++)
d[i] = ;
d[s] = cap ;
bool flag ;
for (int i = ; i <= n ; i++) {
flag = ;
for (int j = ; j < cnt ; j++) {
if (d[e[j].v] < ( d[e[j].u] - e[j].c ) * e[j].r ) {
flag = ;
d[e[j].v] = ( d[e[j].u] - e[j].c ) * e[j].r ;
}
}
if (flag)
return false ;
} return true ;
} int main ()
{
freopen ("a.txt" , "r" , stdin) ;
scanf ("%d%d%d%lf" , &n , &m , &s , &cap) ;
while (m--) {
scanf ("%d%d%lf%lf" , &e[cnt].u , &e[cnt].v , &e[cnt].r , &e[cnt].c) ;
cnt++;
e[cnt].u = e[cnt - ].v , e[cnt].v = e[cnt - ].u ;
scanf ("%lf%lf" , &e[cnt].r , &e[cnt].c) ;
cnt++;
}
/*for (int i = 0 ; i < cnt ; i++)
printf ("u = %d , v = %d , e[i].r = %.2f , e[i].c = %.2f\n" , e[i].u , e[i].v , e[i].r , e[i].c) ;*/
if (Bellman_ford())
puts ("YES") ;
else
puts ("NO") ; return ;
}

Currency Exchange(Bellman-ford)的更多相关文章

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

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

  2. POJ 1860 Currency Exchange (最短路)

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

  3. POJ 1860 Currency Exchange (bellman-ford判负环)

    Currency Exchange 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/E Description Several c ...

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

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

  5. Currency Exchange(最短路)

    poj—— 1860 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 29851   Ac ...

  6. POJ1860 Currency Exchange(bellman-ford)

    链接:http://poj.org/problem?id=1860 Currency Exchange Description Several currency exchange points are ...

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

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

  8. Currency Exchange(SPFA判负环)

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

  9. poj1860 兑换货币(bellman ford判断正环)

    传送门:点击打开链接 题目大意:一个城市有n种货币,m个货币交换点,你有v的钱,每个交换点只能交换两种货币,(A换B或者B换A),每一次交换都有独特的汇率和手续费,问你存不存在一种换法使原来的钱更多. ...

随机推荐

  1. 学习笔记——Maven实战(八)常用Maven插件介绍(下)

    我们都知道Maven本质上是一个插件框架,它的核心并不执行任何具体的构建任务,所有这些任务都交给插件来完成,例如编译源代码是由maven- compiler-plugin完成的.进一步说,每个任务对应 ...

  2. Xilinx命名规则

    xilinx公司的FPGA种类繁多,知道了命名规则,看起来应该会舒服很多. 1.xilinx的FPGA命名规则 Xilinx的ug112第一章中介绍了Xilinx公司的FPGA命名规则.一般而言,大的 ...

  3. 结合php ob函数理解缓冲机制

    对于一个刚刚入门的php程序员来说,php缓冲区是几乎透明的.在他们心目中,一个echo print_r 函数,数据便会‘嗖’的一声飞到浏览器上,显示出来.我也一直如此单纯地认为. 其实,在技术的世界 ...

  4. Jsp语法、指令及动作元素

    一.JSP的语法 1.JSP的模板元素:(先写HTML) 就是JSP中的那些HTML标记 作用:页面布局和美化 2.JSP的Java脚本表达式: 作用:输出数据到页面上 语法:<%=表达式%&g ...

  5. openwrt的路由器重置root密码

    家里路由器刷了openwrt,结果长期没登录,忘了root密码. 很容易就找到了这里介绍的办法  http://www.openwrt.org.cn/bbs/thread-12327-1-1.html ...

  6. [wikioi2144]砝码称重2(另类的dfs)

    题目描述 Description 有n个砝码,现在要称一个质量为m的物体,请问最少需要挑出几个砝码来称? 注意一个砝码最多只能挑一次 输入描述 Input Description 第一行两个整数n和m ...

  7. 09.C#委托转换和匿名方法(五章5.1-5.4)

    今天将书中看的,自己想的写出来,供大家参考,不足之处请指正.进入正题. 在C#1中开发web form常常会遇到使用事件,为每个事件创建一个事件处理方法,在将方法赋予给事件中,会使用new Event ...

  8. java web名词解释

    来源于:http://www.cnblogs.com/yxnchinahlj/archive/2012/02/24/2366110.html PO(persistant object) 持久对象 在o ...

  9. iOS边练边学--父子控制器之自定义控制器的切换

    一.如图所示的界面,按钮One.Two.Three分别对应三个控制器的view,点击实现切换.个人感觉父子控制器的重点在于,控制器的view们之间建立了父子关系,控制器不建立的话,发生在view上面的 ...

  10. NServiceBus 结合 RabbitMQ 使用

    参考官方教程: Step by Step Guide 新建4个项目: A Console Application named Client A Console Application named Se ...