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 ;
}

最新文章

  1. Varnish简介
  2. node.js整理 02文件操作-常用API
  3. iOS对象序列化
  4. Redis 安全
  5. VC++6.0环境下调试c语言代码的方法和步骤_附图
  6. linux下nagios的安装与部署
  7. video标签MP4兼容chrome问题
  8. 如何降低90%Java垃圾回收时间?以阿里HBase的GC优化实践为例
  9. Python 好用得让人发指的函数参数语法糖
  10. PHP 多维数组排序 函数怎么保持数字键不被重新索引
  11. vue 时间过滤
  12. Linux shell 时间操作(取昨天 前天)
  13. java自动装箱的一个例子
  14. gitlab 10.8.1 迁移
  15. Node.js最新技术栈之Promise篇
  16. Effective TensorFlow Chapter 4: TensorFlow中的广播Broadcast机制【转】
  17. 初探Angular_02 感受添加组件
  18. System 类的使用
  19. PHP和javascript中url编码解码详解
  20. (一) ffmpeg filter学习-使用流程

热门文章

  1. EF实体框架之CodeFirst三
  2. 原生JS、CSS实现的转盘效果(目前仅支持webkit)
  3. 分享两个你可能不知道的Java小秘密
  4. Git.Framework 框架随手记--ORM查询返回实体对象
  5. 【OpenCV入门教程之一】 安装OpenCV:OpenCV 3.0 +VS 2013 开发环境配置
  6. Spring-事物配置
  7. myeclipse6.0 序列号生成器源码
  8. Learn sed using these command on Linux(流线式编辑器——sed)
  9. TinyMCE(富文本编辑器)
  10. Oracle11g 32位安装步骤