(最短路 SPFA)Currency Exchange -- poj -- 1860
链接:
http://poj.org/problem?id=1860
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 23261 | Accepted: 8419 |
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
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <queue>
#include <algorithm>
using namespace std; #define N 1100 int Head[N], cnt, n;
double V, vv[N]; ///vv中记录的是兑换到此种货币的最大值 struct node
{
int u, v;
double rate, commission;
int next;
}a[N]; void Init()
{
memset(Head, -, sizeof(Head));
memset(vv, , sizeof(vv));
cnt = ;
} void Add(int u, int v, double rate, double commission)
{
a[cnt].u = u;
a[cnt].v = v;
a[cnt].rate = rate;
a[cnt].commission = commission;
a[cnt].next = Head[u];
Head[u] = cnt++;
} int SPFA(int s)
{
queue<int>Q;
Q.push(s); while(Q.size())
{
int p = Q.front(); Q.pop(); for(int i=Head[p]; i!=-; i=a[i].next)
{
int u = a[i].u;
int v = a[i].v;
double k = (vv[u]-a[i].commission) * a[i].rate; if(vv[v] < k)
{
vv[v] = k;
Q.push(v);
}
} if(vv[s]>V)
return ;
}
return ;
} int main()
{
int m, s; while(scanf("%d%d%d%lf", &n, &m, &s, &V)!=EOF)
{
int i, u, v;
double rate1, rate2, commission1, commission2; Init();
for(i=; i<=m; i++)
{
scanf("%d%d%lf%lf%lf%lf", &u, &v, &rate1, &commission1, &rate2, &commission2);
Add(u, v, rate1, commission1);
Add(v, u, rate2, commission2);
} vv[s] = V; int ans = SPFA( s ); if(ans)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
(最短路 SPFA)Currency Exchange -- poj -- 1860的更多相关文章
- 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的税,公式 ...
- Currency Exchange - poj 1860
Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22111 Accepted: 7986 Description Seve ...
- Currency Exchange POJ - 1860 spfa判断正环
//spfa 判断正环 #include<iostream> #include<queue> #include<cstring> using namespace s ...
- kuangbin专题专题四 Currency Exchange POJ - 1860
题目链接:https://vjudge.net/problem/POJ-1860 大致题意:有不同的货币,有很多货币交换点,每个货币交换点只能两种货币相互交换,有佣金C,汇率R. 每次交换算一次操作, ...
- (最短路 spfa)Wormholes -- poj -- 3259
http://poj.org/problem?id=3259 Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions ...
- poj - 1860 Currency Exchange Bellman-Ford 判断正环
Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你 ...
- POJ 1860——Currency Exchange——————【最短路、SPFA判正环】
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- 最短路(Bellman_Ford) POJ 1860 Currency Exchange
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...
随机推荐
- 东芝笔记本Satellite M40-A
1. 问题:开机F2/Fn+F2进入不了BIOS 原因:当安装了Windows10/Windows8并且开启了快速启动,开机F2会进入不了BIOS或者F12进入不了U盘启动选择 解决方法:进入 开始- ...
- Django Admin定制
Django内置的Admin是对于model中对应的数据表进行增删改查提供的组件,使用方式有: 依赖APP: django.contrib.auth django.contrib.contenttyp ...
- erlang程序发布的时候需要注意的地方
假如你的程序依赖三方application,比如cowboy,启动三方程序有两种方式 在erl脚本里面手工启动,这种在使用rebar generate打包的时候和发布beam的时候都可以用 appli ...
- jsp页面的基本语法
JSP全称Java Server Pages,顾名思义就是运行中java服务器中页面,也就是在我们JavaWeb中的动态页面,其本质就是一个Servlet. 学习jsp的基本语法主要就是学习服务器是如 ...
- 在 Ubuntu 16.04 LTS 上 离线安装 Docker / Docker-compose
前情提要 今天上班后,突然接到现场的工程师的电话: XXX的现场环境组的的局域网,上不了互联网.bla bla bla..... 如果需要安装其他软件的话,只能是自己带过去安装... 听完现场工程师的 ...
- Docker系列06:Linux修改docker镜像和容器数据存储位置
指定镜像和容器存放路径的参数是--graph=/var/lib/docker,其默认存储位置为/var/lib/docker, Docker 的配置文件可以设置大部分的后台进程参数,在各个操作系统中的 ...
- 将python源文件打包成exe文件
pyinstaller 库的使用PyInstaller是一个十分有用的第三方库,它能够在Windows.Linux.Mac OS X 等操作系统下将 Python 源文件打包,通过对源文件打包,Pyt ...
- 在线OFFICE方案
Office在线预览及PDF在线预览的实现方式大集合 在线浏览office 文件 在线预览文档openoffice+swfTool 类百度文库文档上传.转换和展示功能项目开源代码 微软的office ...
- FireDAC 汉字字段名称过滤
[FireDAC][Stan][Eval]-107. Invalid character found [ 拼音码 like '%A%' ] 英文字段名称过滤正常 汉字字段名过滤报错. 莫非不支持汉字字 ...
- bootargs中ip段各项解释
目标板:合众达的SEED-DVS6467开发板 内核版本:2.6.10 最近同事测试板卡nfs挂载PC的文件系统时出现点问题,PC上ifconfig中显示以太网为eth3,然而板卡启动参数列表相关信息 ...