Currency Exchange

Time Limit: 1000MS Memory Limit: 30000K

Total Submissions: 22180 Accepted: 8015

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

题意就是不同钱之间有着兑换比例和要交的费用

问经过一系列的兑换后可不可是自己的钱增多

#include <iostream>
#include <cstdio>
#include <cstring>
#define exp 1e-9
#define INF 0x3f3f3f3f using namespace std; const int Max=110; struct node
{
int v;
int u;
double rate;
double com;
} Edge[2*Max];
double dis[Max];
int n,m;
int M; bool Bellman_Ford(int s,double v)
{
memset(dis,0,sizeof(dis));
dis[s]=v;
bool flag;
while(dis[s]<=v+exp)
{
double ans;
flag=true;
for(int i=0; i<M; i++)
{
ans=(dis[Edge[i].u]-Edge[i].com)*Edge[i].rate;
if(dis[Edge[i].v]+exp<ans)
{
dis[Edge[i].v]=ans;
flag=false;
}
}
if(flag)
{
if(dis[s]>v)
{
return true;
}
else
return false;
}
}
return true;
}
int main()
{
int s; double V;
int u,v;
double Ruv,Cuv,Rvu,Cvu;
while(~scanf("%d %d %d %lf",&n,&m,&s,&V))
{
M=0;
for(int i=0; i<m; i++)
{
scanf("%d %d %lf %lf %lf %lf",&u,&v,&Ruv,&Cuv,&Rvu,&Cvu);
Edge[i].u=u;
Edge[i].v=v;
Edge[i].rate=Ruv;
Edge[i].com=Cuv;
M++;
Edge[i+m].u=v;
Edge[i+m].v=u;
Edge[i+m].rate=Rvu;
Edge[i+m].com=Cvu;
M++;
}
if(Bellman_Ford(s,V))
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Currency Exchange 分类: POJ 2015-07-14 16:20 10人阅读 评论(0) 收藏的更多相关文章

  1. Mahout快速入门教程 分类: B10_计算机基础 2015-03-07 16:20 508人阅读 评论(0) 收藏

    Mahout 是一个很强大的数据挖掘工具,是一个分布式机器学习算法的集合,包括:被称为Taste的分布式协同过滤的实现.分类.聚类等.Mahout最大的优点就是基于hadoop实现,把很多以前运行于单 ...

  2. iOS开发网络数据之AFNetworking使用 分类: ios技术 2015-04-03 16:35 105人阅读 评论(0) 收藏

    http网络库是集XML解析,Json解析,网络图片下载,plist解析,数据流请求操作,上传,下载,缓存等网络众多功能于一身的强大的类库.最新版本支持session,xctool单元测试.网络获取数 ...

  3. iOS开源库--最全的整理 分类: ios相关 2015-04-08 09:20 486人阅读 评论(0) 收藏

    youtube下载神器:https://github.com/rg3/youtube-dl 我擦咧 vim插件:https://github.com/Valloric/YouCompleteMe vi ...

  4. iOS自定义字体及类目 分类: ios技术 2015-05-15 16:34 195人阅读 评论(0) 收藏

    1:获取字体文件 从各种渠道下载字体文件ttf, 网站或者从别的ipa里扣出来.(以fzltxh.ttf为例) 2:将fzltxh.ttf文件拷贝到工程中 3:在Info.plist中添加项: Fon ...

  5. NPOI 通用导出数据到Excel 分类: C# Helper 2014-11-04 16:06 246人阅读 评论(0) 收藏

    应用场景: 在项目中,经常遇到将数据库数据导出到Excel,针对这种情况做了个程序封装.工作原理:利用NPOI将SQL语句查询出的DataTable数据导出到Excel,所见即所得. 程序界面:   ...

  6. ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 175人阅读 评论(0) 收藏

    一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...

  7. ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 174人阅读 评论(0) 收藏

    一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...

  8. JAVA 对象数组,加载图片实例 分类: Java Game 2014-08-14 16:57 80人阅读 评论(0) 收藏

    主函数: package com.mywork; import java.awt.Color; import java.awt.Image; import javax.swing.ImageIcon; ...

  9. Hdu 1010 Tempter of the Bone 分类: Translation Mode 2014-08-04 16:11 82人阅读 评论(0) 收藏

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

随机推荐

  1. 《30天自制操作系统》04_day_学习笔记

    harib01a: P65 用C语言实现内存写入 实现一个往黑画面上写入东西的函数 修改了naskfunc.nas中的内容 在bootpack.c中 用write_mem8()函数将VRMA中全部写入 ...

  2. 【Origin】 破阵子-未可留 征人调

    几朝岁月,悠悠,容颜改,两鬓衰,可恨荣光不留! 一生事,忧心畔,可怜惶惶,不拿年岁当缠头: 只把扑朔往往,人生几回首: 等闲识得料峭处,一腔泪流: 曾记否,三十功名尘与土,不可解忧愁: 青春换得明日花 ...

  3. [原创]安装Oracle 11gR2,以及如何在win8下使用plsql develper连接Oracle数据库 ,在这里和大家分享下

    一,关于win8下安装Oracle 11gR2 1.我下载的是Oracle_11gR2_win64.其中有两个包: 注意:在解压了之后将:win64_11gR2_database_2of2\datab ...

  4. JetBrains公司介绍(Java、Python、PHP、Ruby、前端和代码测试与重构的IDE)

    JetBrains JetBrains是一家捷克的软件开发公司,该公司位于捷克的布拉格,并在俄国的圣彼得堡及美国麻州波士顿都设有办公室,该公司最为人所熟知的产品是Java编程语言开发撰写时所用的集成开 ...

  5. 解决maven编译spark1.5报错问题

    spark1.5发布了,赶紧去下了源码尝鲜 git clone git://github.com/apache/spark.git -b branch-1.5 输入命令进行编译 ./make-dist ...

  6. linux强制umount设备的方法

    假如挂载时使用了:mount /dev/sda1 /mnt/sda1 #查找占用设备的pid fuser -m /mnt/sda1 #假如此时得到的pid为12345 kill -9 12345 um ...

  7. 典型的检查对float精度理解的代码

    -rand()%); vy = ); vz = ); pList_particle[i].m_velocity = Vector3(vx,vy,vz); ... 1,3行代码的vx和vz的值域可以通过 ...

  8. SQL数据库之变量

    --学习SQL数据库,变量是必须要掌握的概念,系统变量就是变量中最重要的变量之一,下面是SQL中系统变量的应用实例 use AdventureWorksDW exec sp_addtype 'char ...

  9. selenium 右键另存为操作

    from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsbrowse ...

  10. cornerstone的简单使用

    第一步打开工具点击左下角那个加号,弹出的选项中选Add Repository..或者直接点中间显示的Add Repository...是一样的 第二步: 下面填的内容是你经理给你的账号和密码,你只要c ...