Currency Exchange POJ1860
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
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
题意:
大概就是换钱,交换点是1~N,每个点都能把相应的钱转换为另一种,(本金-手续费)*汇率=转换后所得的钱。
问你能不能让他的钱变多。
思路:
要自闭了,这么难的英文,看半天都看不懂。。。。。N,M,S,V:分别代表N个交换点,m种转换方式,S是初始的货币种类(即与源点),V是拥有的S类货币数量,每行输入 A、B、RAB、CAB、RBA、CBA 分别为A、B两种货币,A换成B的汇率以及手续费,B换成A的汇率以及手续费。把题看为求源点到其他点的最短路径即可,用Bellman-ford判断是否有正环即可(因为是想让钱那边多)。
代码:
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <limits>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define Sci(x) scanf("%d",&x)
#define Sci2(x, y) scanf("%d%d",&x,&y)
#define Sci3(x, y, z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%I64d",&x)
#define Scl2(x, y) scanf("%I64d%I64d",&x,&y)
#define Scl3(x, y, z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define Pri(x) printf("%d\n",x)
#define Prl(x) printf("%I64d\n",x)
#define For(i,x,y) for(int i=x;i<y;i++)
#define FFor(i,x,y) for(int i=x;i>y;i--)
#define For_(i,x,y) for(int i=x;i<=y;i++)
#define FFor_(i,x,y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define LL long long
#define ULL unsigned long long
#define MAXSIZE 255
#define INF 0x3f3f3f3f
const int mod = 1e9+;
const double PI = acos(-1.0); using namespace std;
struct node
{
int s;
int e;
double r;
double c;
} edge[MAXSIZE];
double dis[MAXSIZE];//dis[i]表示当货币种类为i时钱的数目
int n,m,s;
double v;//钟类,交换点 哪个 多少钱,
void bellman(int k)
{
Mem(dis,);//这个地方初始化为0,因为要判断是否有正环
dis[s]=v;//源点距离为v即他最开始拥有的钱
For(i,,n)
For(j,,k)
{
node data=edge[j];
if(dis[data.e]<(dis[data.s]-data.c)*data.r)//此处用的小于号,松弛找到做多的钱
dis[data.e]=(dis[data.s]-data.c)*data.r;
}
For(i,,k)
{
node data=edge[i];
if(dis[data.e]<(dis[data.s]-data.c)*data.r )//说明有正环
{
printf("YES\n");
return ;
}
}
printf("NO\n");
}
int main()
{
// int x,y,z;
//if(dis[edge[i].e]<dis[edge[]])
//scanf("%d%d%d%d",)
Sci3(n,m,s);
scanf("%lf",&v);
int s,e;
int k=;
while(m--)
{
Sci2(s,e);
edge[k].s=s;
edge[k].e=e;
scanf("%lf%lf",&edge[k].r,&edge[k].c);
k++;
edge[k].s=e;
edge[k].e=s;
scanf("%lf%lf",&edge[k].r,&edge[k].c);
k++;
}
bellman(k);
return ;
}
Currency Exchange POJ1860的更多相关文章
- Bellman_ford 算法 Currency Exchange POJ1860
Bellman_ford算法用于寻找正环或者负环! 算法导论: 24.1 The Bellman-Ford algorithm The Bellman-Ford algorithm solves th ...
- POJ1860——Currency Exchange(BellmanFord算法求最短路)
Currency Exchange DescriptionSeveral currency exchange points are working in our city. Let us suppos ...
- POJ1860 Currency Exchange(bellman-ford)
链接:http://poj.org/problem?id=1860 Currency Exchange Description Several currency exchange points are ...
- poj1860 bellman—ford队列优化 Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22123 Accepted: 799 ...
- POJ1860 Currency Exchange【最短路-判断环】
Several currency exchange points are working in our city. Let us suppose that each point specializes ...
- POJ1860:Currency Exchange(BF)
http://poj.org/problem?id=1860 Description Several currency exchange points are working in our city. ...
- poj1860 Currency Exchange(spfa判断正环)
Description Several currency exchange points are working in our city. Let us suppose that each point ...
- POJ1860 Currency Exchange —— spfa求正环
题目链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Tota ...
- POJ-1860 Currency Exchange( Bellman_Ford, 正环 )
题目链接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...
随机推荐
- 开源joda-time使用demo
开源joda-time 1.maven中引入 <dependency> <groupId>joda-time</groupId> <artifactId> ...
- usb口打印机的指令打印和驱动打印
打印机简介:是计算机的输出设备之一,用于将计算机处理结果打印在相关介质上. 打印机类型:激光打印机.喷墨打印机.针式打印机.热敏打印机等. 计算机和打印机之间的连接方式:usb口.串口.并口.网口.蓝 ...
- kuberbetes基础概念
部署了一大堆,来了解一下K8S一些基本的概念. 1.Node Node作为集群中的工作节点,运行真正的应用程序,在Node上Kubernetes管理的最小运行单元是Pod.Node上运行着Kubern ...
- 如何将 qsys 子模块设置为参数可调的方式给另外的qsys 调用
Intel FPGA Quartus 软件中的 Qsys工具 也就是 Platform Designer 系统集成工具,可以 图形化界面操作 使用系统自带ip,自定义ip 系统自动生成 ip 间的连接 ...
- 从零到一,利用kubeadm在ubuntu server 16.04 64位系统离线安装kubernetes v1.10.0
说明 初步接触kubernets,记录学习过程 本教程目的利用kubeadm在ubuntu server 16.04 64位系统离线安装kubernets v1.10.0 环境信息 节点IP地址 角色 ...
- Python浮点数(小数)运算误差的原因和解决办法
原因解释:浮点数(小数)在计算机中实际是以二进制存储的,并不精确.比如0.1是十进制,转换为二进制后就是一个无限循环的数:0.0001100110011001100110011001100110011 ...
- 阿里云服务器CentOS7.5安装RabbitMQ
RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件).RabbitMQ服务器是用Erlang语言编写的,而集群和故障转移是构建在开放电信平台框架上的. 为什么 ...
- 2018.7.16 题解 2018暑假集训之Roads-roads
题面描述 有标号为1--n的城市与单行道相连.对于每条道路有两个与之相关的参数:道路的长度以及需要支付的费用(用硬币的数量表示) 鲍勃和爱丽丝曾经生活在城市1.在注意到爱丽丝在他们喜欢玩的卡牌游戏中作 ...
- 几款常用的在线API管理工具(是时候抛弃office编写接口文档了)
在项目开发过程中,总会涉及到接口文档的设计编写,之前使用的都是ms office工具,不够漂亮也不直观,变更频繁的话维护成本也更高,及时性也是大问题.基于这个背景,下面介绍几个常用的API管理工具,方 ...
- springboot+druid连接池及监控配置
1. 问题描述 阿里巴巴的数据库连接池Druid在效率与稳定性都很高,被很多开发团队使用,并且自带的Druid监控也很好用,本章简单介绍下springboot+druid配置连接池及监控. 2. 解决 ...