Currency Exchange (SPFA)

Currency Exchange(spfa,邻接矩阵) 题目意思:给出 N 种 currency, M种兑换方式,Nick 拥有的的currency 编号S 以及他的具体的currency(V)。M 种兑换方式中每种用6个数描述: A, B, C, D,E, F。其中,C: 货币A 兑换 货币B 的汇率为C,佣金为D。E:货币B 兑换 货币 A 的汇率,佣金为F。假设含有的A货币是x,那么如果兑换成B,得到的货币B 就是:(x-D) * C。问从 货... 阅读详情
Problem 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 BA and 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<sup>3</sup>.< br>For each point exchange rates and commissions are real, given with at most two digits after the decimal point, 10<sup>-2</sup><=rate<=10<sup>2</sup>, 0<=commission<=10<sup>2</sup>.< br>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<sup>4</sup>.< br>
 

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
 
Problem 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 BA and 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<sup>3</sup>.< br>For each point exchange rates and commissions are real, given with at most two digits after the decimal point, 10<sup>-2</sup><=rate<=10<sup>2</sup>, 0<=commission<=10<sup>2</sup>.< br>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<sup>4</sup>.< br>
 

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
换钱问题:
给出n种钱,m个站点,现在有第 s种钱,身上有v 这么多;
下面 m行 站点有a,b两种钱,rab a->b的汇率,cab a-->b的手续费, 相反rba cba ; 
问在10辞职内,能不能把钱换的变的多了?

SPFA方法:

#if 0
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
const int N = 110;
int n, m, s;
double dis[N], v, rate[N][N], cost[N][N];

bool spfa(int start)
{
    bool inq[110];
    memset(inq, 0, sizeof(inq));
    memset(dis, 0, sizeof(dis));
    dis[start] = v;
    queue<int> Q;
    Q.push(start);
    inq[start] = true;
    while(!Q.empty())
    {
        int x = Q.front();
        Q.pop();
        inq[x] = false;
        for(int i = 0; i <= n; i++)
        {
            if(dis[i] < (dis[x] - cost[x][i]) * rate[x][i])
            {
                dis[i] = (dis[x] - cost[x][i]) * rate[x][i];
                if(dis[start] > v)
                    return true;
                if(!inq[i])
                {
                    Q.push(i);
                    inq[i] = true;
                }
            }
        }
    }
    return false;
}

int main()
{
    int i, j;
    while(~scanf("%d%d%d%lf",&n,&m,&s,&v))
    {
        int a, b;
        double rab, rba, cab, cba;
        for(i = 1; i <= n; i++)
            for(j = 1; j <= n; j++)
            {
                if(i == j)
                    rate[i][j] = 1;
                else
                    rate[i][j] = 0;
                cost[i][j] = 0;
            }
        for(i = 0; i < m; i++)
        {
            scanf("%d%d%lf%lf%lf%lf",&a,&b,&rab,&cab,&rba,&cba);
            rate[a][b] = rab;
            rate[b][a] = rba;
            cost[a][b] = cab;
            cost[b][a] = cba;
        }
        if(spfa(s))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
#endif




Windows 2000系统下载与全套镜像安装:从镜像校验到驱动兼容性实战指南 操作系统镜像文件是安装系统的核心载体,其完整性直接影响部署成败。哈希校验作为验证文件一致性的基础手段,能有效避免因镜像损坏导致的安装中断。对于已停止支持的操作系统,如Windows 2000,其镜像获取与安装更具挑战性,但它在工业控制、专用终端及怀旧技术研究中仍有不可替代的价值。通过理解镜像命名规则、服务包等级(如SP4)及引导方式,结合虚拟机或老硬件平台,可以顺利完成部署。同时,驱动兼容性是老系统运行的关键瓶颈,需针对性解决网卡、显卡等外设驱动问题。本文从镜像下载、校验到安装配置,系统梳理了Windows 阅读详情

相关推荐

Unity 升级引擎版本后构建报错:script class layout is incompatible between the editor and the player

Unity升级引擎版本后,项目报错:script class layout is incompatible between the editor and the player。

学习与分享 593

Currency Exchange (判断负环,代码极短)

题目 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

hjc的博客 3018

山东大学FPGA课程实验一 加法器设计

电子设计自动化与FPGA设计,实验一 加法器设计

2503_91283667的博客 869

Currency Exchange——最短路Bellman-Ford算法

【题目描述】 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. Th...

T_T233333333的博客 431

Adams与Matlab联合仿真入门:从零搭建你的第一个动力学模型

本文为Adams与Matlab联合仿真新手提供了一份详尽的入门指南。文章从软件环境配置、版本兼容性检查讲起,逐步演示了如何在Adams中构建单摆动力学模型并定义输入输出接口,以及在Matlab/Simulink中搭建控制回路。通过一个完整的受控单摆实例,手把手教你完成从模型导出、模块生成到执行联合仿真的全流程,帮助你快速搭建并运行第一个联合仿真模型,实现动力学与控制系统的协同验证。

g5h6i7j的博客 699

OnePose++: Keypoint-Free One-Shot Object Pose Estimation without CAD Models

算法:首先采用LoFTR的细匹配模块,将粗匹配点周围的小窗口内,通过对比特征找到最相似的位置,细化当前特征点的位置。算法:PnP算法,利用3D点和2D投影点的对应关系,计算相机相对于物体的6D姿态(位置朝向)。算法:使用COLMAP,对2D粗匹配对(不依赖传统关键点匹配)进行特征轨迹计算并生成半稠密点云,每个3D点包含坐标和对应的2D投影点。算法:LoFTR粗匹配模块,将每一个像素点视为伪关键点,生成半稠密的2D匹配对。输入:优化后的3D、当前视图的2D特征点。输出:粗半稠密点云以及物体的特征轨迹。

雨落倾城的博客 885

Currency Exchange(判断正权回路)

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...

weixin_44694282的博客 1464

Laravel 结合 jwt-auth 实现无状态 API 认证(实战解析)

本文详细解析了如何在Laravel框架中结合jwt-auth实现无状态API认证,包括JWT的优势、环境搭建、Token签发与刷新、API路由保护等实战内容。通过具体代码示例和优化技巧,帮助开发者高效解决跨域认证问题,提升系统安全性。

weixin_29315569的博客 210

E - Currency Exchange POJ - 1860( 找正回路 + 反向Bellman_ford)

E - Currency Exchange POJ - 1860 Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations on...

石旭先森的博客 308

操作系统期末大题类型题解

额,OS主要这回考程序分析题,PV操作、生产者消费者啊,哲学家进餐问题,死锁问题啊,如何避免死锁,经典银行家算法,页面置换算法啥的,磁盘调度......总计还有很多,就不一一说了 PV操作 谈到PV操作,首先要了解什么是信号量,其实就是用来解决互斥与同步问题的,分为原语wait(S)和signal(S),也就是我们常说的PV操作,在这里给出王道上的概念 wait(S){ while(S>0) S=S-1; } signal(S){ S=S+1; } 记录型信号量

ZXxxiaoxuan的博客 792

同济大学C++mooc第五、六讲参考答案

同济大学C++moooc第5、6讲 第五讲 第一题 随机产生10个30~100(包括30,100)的正整数,求它们的最大值、最小值、平均值,并显示整个数组的值和结果。 代码片. // #include<iostream> const int n = 10; using namespace std; int main() { int s[n],i,j,t,sum=0; for (i = 0; i < n; i++)

cjzui6666的博客 1万+

Currency Exchange (最短路)

    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. Ther...

Z2Min_ 905

K230在原有LVGL控件触摸屏控制的基础上,增加USB鼠标控制!

搭配CanMV图形化编程,中小学生可快速开发“键鼠控制AI小游戏”“智能画板”等趣味项目,降低AI学习门槛;:HDMI屏幕+键鼠组合,直接在开发板上调试代码、修改ISP参数、查看AI推理日志,无需频繁连接电脑;:打造带交互的AI设备(如工业控制面板、智能显示器),鼠标操作菜单、键盘输入指令,体验媲美小型PC;:无网络场景下,通过键盘直接向AI设备录入数据、配置参数,适配野外监测、本地工控等场景。,自动识别、快速响应,完美适配交互控制、参数调试、数据输入等场景。

weixin_47446386的博客 146

POJ - 1860 Currency Exchange SPFA判断正环模版

题目链接 POJ-1860 题意 给定n种货币和m种兑换方式,每种兑换方式有汇率和手续费(A-B和B-A的汇率手续费不一定一样)。给定初始货币种类和数量,问是否可以任意次兑换后实现货币增值(以初始货币计) 解法 将货币看作节点,交换方式看作边。如果存在增值的兑换方式,由于每个兑换可以多次使用,那么可以将货币兑换到无穷多,那么这种兑换方式中有无初始货币也就无所谓了。例如初始货币A,增值兑换方式B-C-D-B,虽然这个兑换中没有A,但因为可以无限次兑换,总能得到一个足够大的货币量,兑换回A仍然增值。那么只需要判

TheSunspot的博客 686

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

《Currency Exchange》spfa(详解)

做完后梳理下这道题。 首先,题意是给我们n种货币,m个货币兑换点,然后有转换规则.问你最后经过一连串转换后,回到起点,你手上的这种货币数量有没有增多 我们将它转化为一个图的问题. 那么就是把n种货币看成n个点,把m个货币兑换点看成m条边,但是注意这条边上存的是转换规则,因为边的权值应该是转换后的货币量,我们一开始不可能知道。 那么,我们再看一下这个提问,问你回到起点后的数量,首先,我们边可以将它看...

weixin_45671214的博客 695

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

Currency Exchange(floyd,dijstra,spfa)

POJ-1860(求是否存在正环回路) 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 onl...

weixin_43870697的博客 512

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

POJ 1860 Currency Exchange SPFA判回路

就是有N种硬币,M个兑换所,每个兑换所可以把A兑换成B或者把B换成A A B Rab Cab Rba Cba可以表示一个兑换所,如果是x个A,则可以兑换成(x-Cab)*Rab个A,如果是x个B,则可以兑换成(x-Cba)*Rba个A, 然后某人现在有V个S种货币,问他能否在经过某些兑换后,最后能得到比V多的S种货币 这个题其实是一个判断回路的问题,类似于判断负权回路,这个题判断的是正权回路

一蓑烟雨任平生 396

POJ 1860 Currency Exchange 【spfa判断正环】

POJ 1860 Currency Exchange 【spfa判断正环】 原题链接:传送门 题目大意: 给出几种货币以及它们正向反向兑换的汇率和手续费, 求给定一种货币以及金额,问能否经过若干次货币兑换后回到原给定的货币种类, 若能实现金额数增加则输入YES,否则输出NO 具体思路: 最短路变形,spfa求解,若换到某种货币金额数大于该种货币原有金额则更新,若发现某条边更新了超过n次,说明存在正...

指弹键盘哼民谣 582

POJ 1860 Currency Exchange spfa

注意,使用spfa算法的时候,一个点进队n+2次说明所有与其相关的点均已经得到了正环的收益,然而除此之外什么都不能说明,在这道题上,也就不可能说明此时某点的值是否可以大于它的初始值。spfa是个神奇的算法,的空一定要好好研究一番。 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;string.h&gt; #include&...

weixin_39399748的博客 284

POJ 1860 Currency Exchange(spfa)

POJ 1860 Currency Exchange Description Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operation...

muyu__的博客 345

Currency Exchange POJ - 1860 Spfa经典例题

Currency Exchange POJ - 1860 Spfa #include<iostream> #include <cstdio> #include <cmath> #include <cstring> #include <string> #include <cmath> #include <stack> #include <queue> #include <vector> #include

Foolishman的博客 475

Poj 1860 Currency Exchange 【spfa算法如何判断负权环】

负权环的判断方法 根据松弛次数 n代表节点个数。 根据松弛次数是否大于等于n来判断负权环,是从网上其他博客说的,根据出队次数是否大于等于n来判断,想到的。因为,判断出队次数,是判断更新次数的上界。 用一个n大小的数组来代表每个点的松弛次数。因为SPFA算法里的松弛,和Bellman-ford算法里的松弛一样。Bellman-ford算法里,对同一个点的松弛次数,在极端情况下,可以想象把这些松弛次数分配到每一次迭代求解中去,而迭代求解一共只有n-1次。所以一旦某个点的松弛次数等于了n,那么就说明有负环。 所以

csyifanZhang的博客 272

【POJ - 1860】 Currency Exchange (SPFA)

描述 有N种货币,M种可以互相兑换(每次扣除一定的手续费) 问能不能经过若干次兑换让钱变多 解决 这看起来挺“最大路”的, 不过由于不同的货币单位没办法选出“当前最大”的货币 所以考虑SPFA 只要经过一定次数的更新,S货币回到S的钱大于初始的就可以return true SPFA执行完都没有触发return true的话就return false 代码 #include<cstdio> #include<queue> const int N=1e2+10; struct qq{

大青蛙的boooooooo客 288

poj 1860 Currency Exchange SPFA

算法: 1.SPFA求最长路,dis【】初始直为0,大于改成小于号 2.松弛结束后,判断是否大于dis[S] > V, 大于就输出YES, 否则输出NO View Code #include <stdio.h> #include <string.h> #include <stdlib.h> #include <q...

weixin_30852419的博客 133

POJ1860Currency Exchange spfa

和上题汇率差不多,只不过多了tax,

GXwar の Code library 601

[POJ 1860] Currency Exchange [spfa]

Currency Exchange 【POJ 1860】 【SPFA】

HIT_Zero的博客 497
上一篇: 训练总结8.7
下一篇: A. Vladik and Courtesy
Joined
博客等级 码龄10年 19粉丝 134原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值