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 ...
随机推荐
- 【OpenJudge3531】【背包DP】【膜法交配律】判断整除
判断整除 总时间限制: 1000ms 内存限制: 65536kB [描述] 一个给定的正整数序列,在每个数之前都插入+号或-号后计算它们的和.比如序列:1.2.4共有8种可能的序列:(+1) + (+ ...
- Ubuntu 16.04将ISO镜像写入U盘
sudo fdisk -l 查看U盘的路径,如/dev/sdc为U盘的位置,注意位置!注意这个不是挂载的位置. 然后准备好ISO文件,如放在/home/jim/abc.iso 然后输入 sudo dd ...
- Android简单的利用SoundPool进行播放铃声的实例代码
MainActivity.java package com.example.pengdonglin.soundpool_demo; import android.annotation.Suppress ...
- 数据库读写锁的实现(C++)
一.基本概念 在数据库中,对某数据的两个基本操作为写和读.分布有两种锁控制:排它锁(X锁).共享锁(S锁). 排它锁(x锁):若事务T对数据D加X锁,则其他不论什么事务都不能再对D加不论什么类型的锁. ...
- LVS/NAT
平台:RedHat Enterprise Linux centos6.3 ipvsadm ipvs 1. NAT模型 NAT模型:地址转换类型,主要是做地址转换,类 ...
- ylbtech-KeFuYunWei(服务运维考核系统)-数据库设计
ylbtech-DatabaseDesgin:ylbtech-KeFuYunWei(服务运维考核系统)-数据库设计 DatabaseName:KEFUYUNWEI Model:Admin 用户后台管理 ...
- ES6里关于模板字面量的拓展
JS 的字符串相对其他语言来说功能总是有限的,事实上,ES5中一直缺乏许多特性,如多行字符串.字符串格式化.HTML转义等.ES6通过模板字面量的方式进行了填补,模板字面量试着跳出JS已有的字符串体系 ...
- ElasticSearch _xpack用户管理
权限管理可以通过kibana的Management界面进行,本篇主要介绍的是通过命令进行权限管理,用户API使您能够从本机域创建,读取,更新和删除用户. 这些用户通常被称为本地用户. 要使用此API, ...
- ambari修改admin密码
https://community.hortonworks.com/questions/449/how-to-reset-ambari-admin-password.html 1) Postgres ...
- 15 Basic ‘ls’ Command Examples in Linux
FROM: http://www.tecmint.com/15-basic-ls-command-examples-in-linux/ ls command is one of the most fr ...