(最短路 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 ...
随机推荐
- 浅析网站建设的PHP,JAVA语言分析
编程绝对是一件不轻松的活儿.随着电子商务在国内成功的推广,京东.苏宁等大型B2C综合网上商城的成功运营,一批批以产业分类的独立网店也如火如荼发展起来.伴随着这股热潮,网店系统等相关衍生开店平台行业也出 ...
- 洛谷4294 [WC2008]游览计划——斯坦纳树
题目:https://www.luogu.org/problemnew/show/P4294 大概是状压.两种转移,一个是以同一个点为中心,S由自己的子集拼起来:一个是S相同.中心不同的同层转移. 注 ...
- bzoj1037生日聚会
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1037 任意区间的话,可以从所有后缀区间考虑. 因为每一个区间一定是某一时刻的一个后缀区间,所 ...
- Qemu创建KVM虚拟机内存初始化流程
转载请注明:[转载自博客xelatex KVM],并附本文链接.谢谢. [注]文章中采用的版本: Linux-3.11,https://www.kernel.org/pub/linux/kernel/ ...
- 复制mysql数据库的步骤
Navicat 转存sql文件 然后命令 mysql -uroot -p123456 dbname < e:/backup/20141014.sql
- Java课程设计---web版斗地主
一. 团队课程设计博客链接 二.个人负责模块和任务说明 负责前后端数据传输 JSP界面的设计 根据后台传来的数据进行页面动态更新 负责Servlet设计 三.自己的代码提交记录截图 四.自己负责模块或 ...
- python编程遇见的异常
import sys print('目前系统的编码为:',sys.getdefaultencoding()) # 目前系统的编码为: utf-8 name = 'this is a test!' pr ...
- 第10课 初探 Qt 中的消息处理
1. Qt消息模型 (1)Qt封装了具体操作系统的消息机制 (2)Qt遵循经典的GUI消息驱动事件模型 2. 信号与槽 (1)Qt中定义了与系统消息相关的概念 ①信号(Signal):由操作系统产生的 ...
- Android开发入门——Button绑定监听事件三种方式
import android.app.Activity; import android.os.Bundle;import android.view.View;import android.widget ...
- Numpy的ndarry:一种多维数组对象
Numpy的ndarry:一种多维数组对象 Numpy最重要的一个特点就是其N维数组对象(即ndarry),该对象是一个快速而灵活的大数据集容器.你可以利用这种数组对整块数据执行一些数学运算,其语法跟 ...