Currency Exchange - poj 1860
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 22111 | Accepted: 7986 |
Description
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
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
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
这题使用Bellman-Ford算法,将判断条件修改一下即可,找到是否有权增加的回路
#include <iostream>
#include<string.h>
using namespace std;
struct exch {
int src, des;
float rate, commission;
} ex[];
int main() {
int cur_num, exp_num, cur;
float init;
float c[];
while (cin >> cur_num >> exp_num >> cur >> init) {
memset(c, , * sizeof(float));
c[cur] = init;
for (int i = ; i < exp_num; i++) {
int a, b;
cin >> a >> b;
ex[ * i].src = a;
ex[ * i].des = b;
cin >> ex[ * i].rate >> ex[ * i].commission;
ex[ * i + ].src = b;
ex[ * i + ].des = a;
cin >> ex[ * i + ].rate >> ex[ * i + ].commission;
}
for (int i = ; i < cur_num ; i++) {
for (int j = ; j < * exp_num; j++) {
if (c[ex[j].des]
< (c[ex[j].src] - ex[j].commission) * ex[j].rate) {
c[ex[j].des] = (c[ex[j].src] - ex[j].commission)
* ex[j].rate;
}
}
}
int flag = ;
for (int j = ; j < * exp_num; j++) {
if (c[ex[j].des] < (c[ex[j].src] - ex[j].commission) * ex[j].rate) {
flag=;
break;
}
}
if(flag==){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
} }
return ; }
Currency Exchange - poj 1860的更多相关文章
- (最短路 SPFA)Currency Exchange -- poj -- 1860
链接: http://poj.org/problem?id=1860 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2326 ...
- Currency Exchange POJ - 1860 (spfa判断正环)
Several currency exchange points are working in our city. Let us suppose that each point specializes ...
- Currency Exchange POJ - 1860 (spfa)
题目链接:Currency Exchange 题意: 钱的种类为N,M条命令,拥有种类为S这类钱的数目为V,命令为将a换成b,剩下的四个数为a对b的汇率和a换成b的税,b对a的汇率和b换成a的税,公式 ...
- kuangbin专题专题四 Currency Exchange POJ - 1860
题目链接:https://vjudge.net/problem/POJ-1860 大致题意:有不同的货币,有很多货币交换点,每个货币交换点只能两种货币相互交换,有佣金C,汇率R. 每次交换算一次操作, ...
- Currency Exchange POJ - 1860 spfa判断正环
//spfa 判断正环 #include<iostream> #include<queue> #include<cstring> using namespace s ...
- poj - 1860 Currency Exchange Bellman-Ford 判断正环
Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你 ...
- 最短路(Bellman_Ford) POJ 1860 Currency Exchange
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...
- POJ 1860 Currency Exchange (最短路)
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)
POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...
随机推荐
- 洛谷 P4538 收集邮票
题目描述 有n种不同的邮票,皮皮想收集所有种类的邮票.唯一的收集方法是到同学凡凡那里购买,每次只能买一张,并且买到的邮票究竟是n种邮票中的哪一种是等概率的,概率均为1/n.但是由于凡凡也很喜欢邮票,所 ...
- Java杂谈1——虚拟机内存管理与对象访问
1.理解JAVA虚拟机的内存管理 运行时的数据区 从java虚拟机的内存分配来看,一个java程序运行时包含了如下几个数据区: a) 程序计数寄存器(Program Counter Regis ...
- 【gcc】warning: control reaches end of non-void function
用gcc编译一个C程序的时候出现这样的警告: warning: control reaches end of non-void function 它的意思是:控制到达非void函数的结尾.就是说你的一 ...
- 【教训】null == '',改造ThinkSNS 系统里面的一个缓存管理函数S()后,留下一个大bug
本来想简化 ThinkSNS 系统里面的一个缓存管理函数: <?php /** * 用来对应用缓存信息的读.写.删除 * $expire = null/0 表示永久缓存,否则为缓存有效期 */ ...
- linux命令详解:jobs命令
转:http://www.cnblogs.com/lwgdream/p/3413571.html 前言 我们可以将一个程序放到后台执行,这样它就不占用当前终端,我们可以做其他事情.而jobs命令用来查 ...
- superobject使用方法
superobject使用方法 ISuperObject.AsObject 可获取一个 TSuperTableString 对象. TSuperTableString 的常用属性: count.Get ...
- 【Linux】CentOS7上安装JDK 和卸载 JDK 【rpm命令的使用】
之前有过一篇在CentOS7上安装JDK的文章:http://www.cnblogs.com/sxdcgaq8080/p/7492426.html 在这里又说一次,是要使用rpm命令安装JDK的rpm ...
- DOM系统学习-基础
DOM介绍 DOM介绍: D 网页文档 O 对象,可以调用属性和方法 M 网页文档的树型结构 节点: DOM将树型结构理解为由节点组成. 节点种类: 元素节点.文本节点.属性节点等 查找元 ...
- kubernetes1.5.2--部署监控服务
本文基于kubernetes 1.5.2版本编写 Heapster是kubernetes集群监控工具.在1.2的时候,kubernetes的监控需要在node节点上运行cAdvisor作为agent收 ...
- WEB安全漏洞与防范
1.XSS 原理是攻击者向有XSS漏洞的网站中输入(传入)恶意的HTML代码,当用户浏览该网站时,这段HTML代码会自动执行,从而达到攻击的目的.如,盗取用户Cookie信息.破坏页面结构.重定向到其 ...