Currency Exchange 分类: POJ 2015-07-14 16:20 10人阅读 评论(0) 收藏
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) 收藏的更多相关文章
- Mahout快速入门教程 分类: B10_计算机基础 2015-03-07 16:20 508人阅读 评论(0) 收藏
Mahout 是一个很强大的数据挖掘工具,是一个分布式机器学习算法的集合,包括:被称为Taste的分布式协同过滤的实现.分类.聚类等.Mahout最大的优点就是基于hadoop实现,把很多以前运行于单 ...
- iOS开发网络数据之AFNetworking使用 分类: ios技术 2015-04-03 16:35 105人阅读 评论(0) 收藏
http网络库是集XML解析,Json解析,网络图片下载,plist解析,数据流请求操作,上传,下载,缓存等网络众多功能于一身的强大的类库.最新版本支持session,xctool单元测试.网络获取数 ...
- iOS开源库--最全的整理 分类: ios相关 2015-04-08 09:20 486人阅读 评论(0) 收藏
youtube下载神器:https://github.com/rg3/youtube-dl 我擦咧 vim插件:https://github.com/Valloric/YouCompleteMe vi ...
- iOS自定义字体及类目 分类: ios技术 2015-05-15 16:34 195人阅读 评论(0) 收藏
1:获取字体文件 从各种渠道下载字体文件ttf, 网站或者从别的ipa里扣出来.(以fzltxh.ttf为例) 2:将fzltxh.ttf文件拷贝到工程中 3:在Info.plist中添加项: Fon ...
- NPOI 通用导出数据到Excel 分类: C# Helper 2014-11-04 16:06 246人阅读 评论(0) 收藏
应用场景: 在项目中,经常遇到将数据库数据导出到Excel,针对这种情况做了个程序封装.工作原理:利用NPOI将SQL语句查询出的DataTable数据导出到Excel,所见即所得. 程序界面: ...
- ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 175人阅读 评论(0) 收藏
一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...
- ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 174人阅读 评论(0) 收藏
一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...
- 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; ...
- 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 ...
随机推荐
- Azure billing 分析
昨天把西欧的2012的VM删掉,在北美新建一个2008的VM,装了sql2005 express 在C盘,这样存储就变成2个位置了,西欧和美国,然后放在那里不操作一天,发现billing多了很多, S ...
- Splay!
#include<cstdio> #include<cstdlib> ; ; ; int lim; struct SplayTree { . int sz[maxn]; . ] ...
- B/S与C/S区别
B/S (Brower/Server)-->浏览器/服务器 程序完全部署在服务器上,用户通过浏览器访问应用程序,它是基于internet产物(在应用服务器中部署运行程序) c/s(Client/ ...
- Servlet里写验证码
public class CodeServlet extends HttpServlet { /** * The doGet method of the servlet. <br> * * ...
- 杭电1241 Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission ...
- EBS常用小常识(转)
值集: 1.编辑信息:取上一个值集所选的数据.(值集关联) WHERE BANK_ACCOUNT_ID = :$FLEX$.CE_BANK_ACCOUNT_NUM_NAME ORDER BY STAT ...
- 安装SQLServer2005错误无法在com+目录中安装和配置程序集
无法在com+目录中安装和配置程序集c:\program files\Microsoft SQL Server\90\DTS\tasks\microsoft.sqlserver.MSMQTASK.DL ...
- JNI 回调小记
javah在eclipse中设置参数:location(javah.exe的位置)working dir(${project_loc}/src) -classpath .;./classes -d $ ...
- HTML5 Web app开发工具Kendo UI Web中Grid网格控件的使用
Kendo UI Web中的Grid控件不仅可以显示数据,并对数据提供了丰富的支持,包括分页.排序.分组.选择等,同时还有着大量的配置选项.使用Kendo DataSource组件,可以绑定到本地的J ...
- 161111、NioSocket的用法(new IO)
今天先介绍NioSocket的基本用法,实际使用一般会采用多线程,后面会介绍多线程的处理方法. 从jdk1.4开始,java增加了新的io模式--nio(new IO),nio在底层采用了新的处理方式 ...