(最短路 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 ...
随机推荐
- open_input_file函数调用结构图(转)
open_input_file函数调用结构图(有些重复的函数调用就略掉了,大致是按流程往下的). 函数大致说明: AVFormatContext *avformat_alloc_context(voi ...
- 【开源推荐】PredictionIO:构建预测功能的机器学习服务器
PredictionIO是一款开源的机器学习服务器,开发工程师和数据分析师可以使用它构建智能应用程序,并且还可以做一些预测功能,比如个性化推荐.发现内容等.好比开发者可以使用数据库服务器过滤信息. P ...
- JpGraph使用详解
微信平台开发的推广支持应用里,为了满足用户渠道推广分析的需要,公众平台提供了生成带参数二维码的接口.使用该接口可以获得多个带不同场景值的二维码,用户扫描后,公众号可以接收到事件推送,借此可以通过统计不 ...
- bzoj4558: [JLoi2016]方
Description 上帝说,不要圆,要方,于是便有了这道题.由于我们应该方,而且最好能够尽量方,所以上帝派我们来找正方形 上帝把我们派到了一个有N行M列的方格图上,图上一共有(N+1)×(M+1) ...
- [Winform][C#]获取系统颜色预定义颜色和现有字体集
转自: http://zhidao.baidu.com/link?url=ozY7tJRNBYHUsImE6jn1psqc8owib7MWcDMEmZw48q8iD9Hz9MWgnQQcBDO0VYO ...
- Python写一个目录检索器
前言: 昨天看了Demon哥发的干货,有了次篇博文 干货链接: https://www.soffensive.com/2018/06/exploiting-blind-file-reads-path. ...
- Servlet讲解
第1章 Servlet的生命周期 1.1.1 Servlet的生命周期概述 1.1.1.1 什么是生命周期 生命周期:一个对象从创建到销毁过程. 1.1.1.2 Servlet的生命周期(*****) ...
- XACT Q&A (转)
XACT Q&A 传送门:http://blog.csdn.net/xoyojank/article/details/4098633
- 在eclipse中的maven工程中执行maven命令的步骤
执行maven命令的步骤: 1.找到maven工程的pom.xml文件,点中右键 2.在弹出的对话框中选择run as 3.在弹出的对话框中输入compile 再执行即可
- 47. Permutations II (Back-Track, Sort)
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...