POJ1860 Currency Exchange(正权环,folyd)

2023-10-06 00:42

本文主要是介绍POJ1860 Currency Exchange(正权环,folyd),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目:

Currency Exchange
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 28540 Accepted: 10657

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 R AB, C AB, R BAand C BA - 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

The first line of the input contains four numbers: N - the number of currencies, M - the number of exchange points, S - the number of currency Nick has and V - the quantity of currency units he has. The following M lines contain 6 numbers each - the description 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<=10 3
For each point exchange rates and commissions are real, given with at most two digits after the decimal point, 10 -2<=rate<=10 2, 0<=commission<=10 2
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 10 4

Output

If Nick can increase his wealth, output YES, in other case output NO to the output file.

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

Source

Northeastern Europe 2001, Northern Subregion

[Submit]   [Go Back]   [Status]   [Discuss]

题目大意:有N种货币,货币之间可以按汇率交换,同时还需要收手续费,当你用100A货币去交换B货币,

假如A到B的汇率为29.75,手续费为0.39,则你可以得到(100-0.39)*29.75 = 2963.3975的B货币。货币

可以一直重复交换,问:能否通过兑换货币之后,增加你手中货币的价值,则输出"YES",否则输出"NO"。

思路:把N种货币看成图上的N个点,当你有数量为V的货币A时,

货币AB之间的权值就是——(V-手续费)*A到B的汇率

这道题就可以转换为求图是否还有可无限增大(含有正权回路)的最大路径。


思路:

这个题最终判定是否存在一个无限增大的正权环,先用folyd跑一次,然后再来一次的时候发现还可以继续松弛,那就证明存在,详细的看注释。

代码:

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define N 100+20
#define M 100000+20
#define inf 0x3f3f3f3f
using namespace std;
int n,m,s;
double v,map[N]= {0},g1[N][N]= {0},g2[N][N]= {0};
int floyd()
{double dis[N];for(int i=1; i<=n; i++)dis[i]=map[i];for(int k=1; k<=n; k++)for(int i=1; i<=n; i++)for(int j=1; j<=n; j++)if((map[i]-g2[i][j])*g1[i][j]>map[j])map[j]=(map[i]-g2[i][j])*g1[i][j];for(int i=1; i<=n; i++)if(dis[i]<map[i])//当进行第二次floyd的时候dis里面的信息是已经更新一次的map里的值,如果还能继续更新那就证明有正权环return 1;return 0;
}
int main()
{while(cin>>n>>m>>s>>v){for(int i=1; i<=m; i++){int a,b;double h_ab,m_ab,h_ba,m_ba;cin>>a>>b>>h_ab>>m_ab>>h_ba>>m_ba;//h_ab代表汇率从a->b,m_ab表示佣金从a->bg1[a][b]=h_ab,g2[a][b]=m_ab;g1[b][a]=h_ba,g2[b][a]=m_ba;}map[s]=v;floyd();if(floyd())cout<<"YES"<<endl;elsecout<<"NO"<<endl;}return 0;
}


这篇关于POJ1860 Currency Exchange(正权环,folyd)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/152421

相关文章

Exchange 服务器地址列表的配置方法与注意事项

Exchange Server 是微软推出的一款企业级邮件服务器软件,广泛应用于企业内部邮件系统的搭建与管理。配置 Exchange 服务器地址列表是其中一个关键环节。本文将详细介绍 Exchange 服务器地址列表的配置方法与注意事项,帮助系统管理员顺利完成这一任务。 内容目录 1. 引言 2. 准备工作 3. 配置地址列表 3.1 创建地址列表 3.2 使用 Exchange

Bellman_Ford变形求最长路+正权回路或spfa——POJ 1860

对应POJ题目:点击打开链接 Currency Exchange Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 20814 Accepted: 7451 Description Several currency exchange points are working in our city. L

ssh_exchange_identification: read: Connection reset by peer

最近为了抢自如的房子在京东云服务器上面跑爬虫脚本,今天突然无法登陆了,ssh 连接报错ssh_exchange_identification: read: Connection reset by peer,经过检查,我的 ip 被 deny 了. 要解决此问题,请进行如下配置检查和修改: 通过 云服务器控制台的管理终端 进入系统。 通过 cat 等指令查看 /etc/hosts.deny中是

关于javamail-with-ms-exchange-no-authentication-mechansims-supported-by-both-server错误的解决办法

最近在写邮件相关的程序的时候碰到一个错误,javamail-with-ms-exchange-no-authentication-mechansims-supported-by-both-server 字面上的意思,身份验证有问题。于是开始google If you're trying to connect to your mail server without authentication,

【RabbitMQ】三种Exchange模式——订阅、路由、通配符模式

前两篇博客介绍了两种队列模式,这篇博客介绍订阅、路由和通配符模式,之所以放在一起介绍,是因为这三种模式都是用了Exchange交换机,消息没有直接发送到队列,而是发送到了交换机,经过队列绑定交换机到达队列。         一、订阅模式(Fanout Exchange):    一个生产者,多个消费者,每一个消费者都有自己的一个队列,生产者没有将消息直接发送到队列,而是发送到了交换机

SSH 远程登录报错:kex_exchange_identification: Connection closed.....

一  问题起因         在公司,使用ssh登录远程服务器。有一天,mac终端提示:`kex_exchange_identification: Connection closed by remote host Connection closed by UNKNOWN port 65535`。 不知道为啥会出现这样的情形,最近这段时间登录都是正常的,不知道哪里抽风了,就提示这个。 二

POJ 1860Currency Exchange(贝尔曼最短路)

题目地址:http://poj.org/problem?id=1860 这个题一道很简单的贝尔曼判环的应用,用贝尔曼判环挺方便的。因为把r,c定义成了整型,错了一晚上。。。 #include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <ct

谷粒商城实战笔记-251-商城业务-消息队列-Exchange类型

文章目录 一,Exchange二,Exchange的四种类型1,direct2,fanout3,topic 三,实操1,创建一个exchange2,创建一个queue3,将queue绑定到exchange 一,Exchange AMQP 中消息的路由过程和 Java 开发者熟悉的 JMS 存在一些差别,AMQP 中增加了 Exchange 和 Binding 的角色。生产者把

132-横向移动-Exchange 服务有账户 CVE 漏洞无账户口令爆破

Exchange服务         Microsoft Exchange Server 是微软公司推出的一款企业级邮件服务器软件,它提供了一套全面的电子邮件服务组件,以及消息和协作系统。Exchange Server 不仅支持电子邮件服务,还提供了日历、联系人管理、任务管理、文档管理、实时会议和工作流等丰富的协作应用。这些功能可以通过Internet浏览器访问,使得用户可以轻松地在不同的设备上

管理Exchange服务器邮件队列

管理Exchange服务器邮件队列       在传递处理邮件时,Exchange使用队列来存放这些邮件。队列是临时存放等待进入下一个处理阶段的邮件的位置。每个队列代表传输服务器按照特定顺序处理的逻辑邮件集。如果邮件长时间停留在一个队列中,就可能出现问题了。 邮件队列类型: 提交队列:指分类程序在收集必须通过传输解析,路由和处理的所有邮件时所使用的永久队列。传输服务器接收的所有邮件进入提