POJ 1860:Currency Exchange
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 22648 | Accepted: 8180 |
Description
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
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
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
题意是给出了M种钱币,N个转换所,每个钱币的转换关系,中间要给转换所交一定的中介费。求是否能够有这样的条件,使得钱在转了一圈之后变多了。
看到只需输入YES/NO这样,不用求具体的单源点最短路径或是所有的,就感觉很符合Bellman。。。还有一点,Bellman和Floyd能够处理负权值的图,但Flyod不能有负环。Dijsktra不能处理含有负权值的图。这题用Bellman只是在给每条边松弛的时候不再是简单的相加了,而是dis[edge[j].s]-edge[j].com)*edge[j].l 。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; struct E{
int s;
int e;
double com;
double l;
}edge[5205]; int N,M,S,edge_num;
double V;
double dis[505]; void addedge(int start,int end,double co,double len)
{
edge_num++; edge[edge_num].s=start;
edge[edge_num].e=end;
edge[edge_num].com=co;
edge[edge_num].l=len;
} bool bellman_ford()
{
int i,j;
for(i=1;i<=N-1;i++)
{
int flag=0;
for(j=1;j<=edge_num;j++)
{
if(dis[edge[j].e]<(dis[edge[j].s]-edge[j].com)*edge[j].l)
{
flag=1;
dis[edge[j].e]=(dis[edge[j].s]-edge[j].com)*edge[j].l;
}
}
if(flag==0)
break;
} for(j=1;j<=edge_num;j++)
{
if(dis[edge[j].e]<(dis[edge[j].s]-edge[j].com)*edge[j].l)
return true;
} return false;
} int main()
{
int i,start,end;
double co,len; edge_num=0;
memset(dis,0,sizeof(dis)); cin>>N>>M>>S>>V; for(i=1;i<=M;i++)
{
cin>>start>>end>>len>>co;
addedge(start,end,co,len); cin>>len>>co;
addedge(end,start,co,len);
}
dis[S]=V;
if(bellman_ford())
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
} return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 1860:Currency Exchange的更多相关文章
- 【POJ 1860】Currency Exchange
[题目链接]:http://poj.org/problem?id=1860 [题意] 给你n种货币,m种货币之间的交换信息; 交换信息以 A,B,RA,CA,RB,CB的形式给出; 即A换B的话假设A ...
- (poj)1806 Currency Exchange
题目链接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...
- POJ 3903:Stock Exchange(裸LIS + 二分优化)
http://poj.org/problem?id=3903 Stock Exchange Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- Currency Exchange POJ - 1860 (spfa)
题目链接:Currency Exchange 题意: 钱的种类为N,M条命令,拥有种类为S这类钱的数目为V,命令为将a换成b,剩下的四个数为a对b的汇率和a换成b的税,b对a的汇率和b换成a的税,公式 ...
- 图论 --- spfa + 链式向前星 : 判断是否存在正权回路 poj 1860 : Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 19881 Accepted: 711 ...
- poj 1860 Currency Exchange :bellman-ford
点击打开链接 Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16635 Accept ...
- 最短路(Bellman_Ford) POJ 1860 Currency Exchange
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...
- (最短路 SPFA)Currency Exchange -- poj -- 1860
链接: http://poj.org/problem?id=1860 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2326 ...
- POJ 1860 Currency Exchange【bellman_ford判断是否有正环——基础入门】
链接: http://poj.org/problem?id=1860 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
随机推荐
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-pencil
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- 载域和运行域的理解(ARM程序是怎么运行的)
对ARM加载域和运行域的理解 一般而言,一个程序包括只读的代码段和可读写的数据段.在ARM的集成开发环境中,只读的代码段和常量被称作RO段(ReadOnly):可读写的全局变量和静态变量被称作RW段( ...
- 《分布式消息中间件实践》P153
问题:我直接把作者的源码拷贝下来(包括xml,resource等,作者应该使用的是Eclipse,我复制到IDEA上),依赖加上.执行P153的步骤,报错如下: Exception in thread ...
- [YOLO]《You Only Look Once: Unified, Real-Time Object Detection》笔记
一.简单介绍 目标检测(Objection Detection)算是计算机视觉任务中比较常见的一个任务,该任务主要是对图像中特定的目标进行定位,通常是由一个矩形框来框出目标. 在深度学习CNN之前,传 ...
- (HN)AHOI2018 转盘
题意: 有 \(n\) 个格子围成一圈,每个格子里有一个物品,每个物品的出现时间为 \(T_i\) .开始时选择一个格子为起点,每个单位时间可以向前走一格或不动,若当前格的物品已出现则将其标记.有 \ ...
- Node.js NPM Package.json
章节 Node.js NPM 介绍 Node.js NPM 作用 Node.js NPM 包(Package) Node.js NPM 管理包 Node.js NPM Package.json Nod ...
- 3 ~ express ~ 静态文件托管
静态资源文件处理 (一)设置静态资源托管目录 /* * 当 用户访问的 url 以 /public 开始 ,那么直接返回对应 __dirname + '/public' 下的文件 . 注意是双下划 ...
- zabbix监控oracle之orabbix安装
zabbix服务器安装配置 zabbixserver中安装该软件 mkdir /opt/orabbix cp orabbix-1.2.3.zip /opt/orabbix cd /opt/orabbi ...
- 出现这样的错误提示: E: Sub-process /usr/bin/dpkg returned an error code
1.$ sudo mv /var/lib/dpkg/info /var/lib/dpkg/info_old //现将info文件夹更名2.$ sudo mkdir /var/lib/dpkg/info ...
- zoj 2314Reactor Cooling
秘制神奇上下界网络流%%% 什么什么有(木)源汇可行流什么的,,看不懂(一下纯属个人sb言论) 看了半天知道点,一个点u,从S连到u的流量是全部流入u的下界,u到T是全部流出u的下界和.(进去出来的约 ...