一.题意 有多个货币交易点,每个只能互换两种货币,兑换的汇率不同,并收取相应的手续费.有N种货币,假定你拥有第S中,数量为V,有M个兑换点.问你能不能通过兑换操作使你最后拥有的S币比起始的时候多. 二.题解 货币的交换是可以重复多次的,所以我们需要找出是否存在正权回路(在这一回路上,顶点的权值能不断增加,即能一直进行松弛),且最后得到的s金额是增加的.说到松弛我们立即会想到Bellman-Ford算法,它的特点是可以处理负权边,并能判断是否存在负环(负权回路).本题题恰恰与bellman-For…
POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) 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…
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details/6645778 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <cmat…
Currency Exchange Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other) Total Submission(s) : 4   Accepted Submission(s) : 2 Problem Description Several currency exchange points are working in our city. Let us suppose that…
原题链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 23055   Accepted: 8328 Description Several currency exchange points are working in our city. Let us suppose that each point specializes…
三道题都是考察最短路算法的判环.其中1860和2240判断正环,3259判断负环. 难度都不大,可以使用Bellman-ford算法,或者SPFA算法.也有用弗洛伊德算法的,笔者还不会SF-_-…… 直接贴代码. 1860 Currency Exchange: #include <cstdio> #include <cstring> int N,M,S; double V; ; int first[maxn],vv[maxn*maxn],nxt[maxn*maxn]; double…
SPFA(Shortest Path Faster Algorithm): 一:基本算法 在求解单源最短路径的时候,最经典的是 Dijkstra 算法,但是这个算法对于含有负权的图就无能为力了,而 Bellman - Ford 算法的复杂度又过于高,这时 SPFA就应运而生了. SPFA 在 Bellman - Ford 算法的基础上进行了改进,使其能够在计算带有负权的图的单源最短路径的基础上,时间复杂度大幅降低. 众所周知 Bellman -Ford 算法会对每条边进行 n - 1 次检查,但…
序 求最短路径的算法有很多,各有优劣. 比如Dijkstra(及其堆(STL-priority_queue)优化),但是无法处理负环的情况: 比如O(n^3)的Floyd算法:比如Bellman-Ford算法,可以处理负环的情况. SPFA算法就是基于Bellman-Ford算法的改进. SPFA,全称为Shortest Path Faster Algorithm,也被很多Oler笑称为Super Fast Algorithm. 无可否认的是,SPFA的效率的确很高. 逻辑与思路 SPFA的核心…
Currency Exchange Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1860 Description Several currency exchange points are working in our city. Let us suppose that each point specializes in two par…
Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 19881   Accepted: 7114 Description Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and pe…