博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1860 - Currency Exchange
阅读量:7120 次
发布时间:2019-06-28

本文共 3642 字,大约阅读时间需要 12 分钟。

Currency Exchange
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 18899   Accepted: 6743

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, C
AB, 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.01 2 1.00 1.00 1.00 1.002 3 1.10 1.00 1.10 1.00

Sample Output

YES

Source

解释一下基本题意,SB—hypo有s货币,价值为V,他想获得很多其它的货币。身为一个妻管严,该怎么办?╮(╯▽╰)╭,无奈。。。货币交换公式 (B货币)  = (A货币总量-佣金)*汇率。

输入N,M,S,V;

以下M行,line 1 代表货币1 到 货币2 的 汇率、佣金,货币2 到 货币1 的 汇率、佣金

line 2 代表货币2 到 货币3 的 汇率、佣金,货币3 到 货币2 的 汇率、佣金

打印SB-hypo是否能添加收入?YES/NO

PS:  没什么难度。就是贝尔曼的模板,敲上就差点儿相同A了,可是WA了两次,以为是精度的问题,可是看了一下DISCUSS之后,发现dis[]的初始化不正确,应该为0,而不INF。由于这个题是逆向使用贝尔曼算法,找的不是负环。且没有负环。并代表就有正欢,仅仅能说明可能存在最短路,而是能够使之钱数无限添加的正环。

#include 
#include
#include
#include
#include
const int INF = 1<<20;const int N = 110;const int Size = 9999;using namespace std;double mapp[N][N];double dis[N],ANS;int n,m,s,l;double num;struct node{ int u,v; double hui,yong;}edge[Size];void init(){ l = 0;//若是找负环,dis[]应该初始化INF for(int i = 0;i
dis[edge[j].u] + edge[j].w; 更新最短路 if(dis[edge[j].v] < (dis[edge[j].u] - edge[j].yong)* edge[j].hui) // 更新相对最长路 { dis[edge[j].v] = (dis[edge[j].u] - edge[j].yong)* edge[j].hui; flag = 1; } } if(flag==0)//更新完成跳出 break; } for(int j = 0;j

版权声明:本文博客原创文章,博客,未经同意,不得转载。

你可能感兴趣的文章
趋势发布SecureCloud云安全技术架构
查看>>
3PAR副总裁谈09年存储虚拟化
查看>>
2009年云计算将引发一场黑客攻击高潮
查看>>
亚信基于AWS构建世界级企业互联网平台
查看>>
达索系统成立“大土木工程达索系统BIM技术推进联盟”深化应用、共享经验
查看>>
猥琐思路复现Spring WebFlow远程代码执行
查看>>
开发平台怎么选?来看看专业人士怎么说
查看>>
移动设备尚未形成DDoS的3个原因
查看>>
《OpenGL编程指南(原书第9版)》——1.4 OpenGL渲染管线
查看>>
《中国人工智能学会通讯》——7.7 结束语
查看>>
勒索软件好多都使用恶意LNK链接文件欺骗用户 来看趋势科技分析新型LNK-PowerShell攻击...
查看>>
《数字逻辑设计与计算机组成》一 第2章 2.1 简介
查看>>
《并行计算的编程模型》一3.5 远程内存访问:put和get
查看>>
思博伦安全专家预测2017年民用和军用全球导航应用面临的更大风险
查看>>
勒索软件指向Flash与Silverlight漏洞
查看>>
人工智能项目正在起飞:这对未来的工作意味着什么?
查看>>
天时、地利、人和,技术成熟推动闪存联盟2.0落地
查看>>
五款可以取代 Slack 的开源工具
查看>>
如何将大数据变成企业的洞察力和行动力?
查看>>
新技术给数据中心带来新风险
查看>>