题意:给你m条路花费时间(双向正权路径),w个虫洞返回时间(单向负权路径),问你他能不能走一圈回到原点之后,时间倒流. 思路:题意有点难看懂,我们建完边之后找一下是否存在负权回路,存在则能,反之不能.判断负权回路可以用一个cnt,这个spfa板子里有. 代码: #include<cstdio> #include<set> #include<vector> #include<cmath> #include<queue> #include<cs…
题意:n种钱,m种汇率转换,若ab汇率p,手续费q,则b=(a-q)*p,你有第s种钱v数量,问你能不能通过转化让你的s种钱变多? 思路:因为过程中可能有负权值,用spfa.求是否有正权回路,dis[s]是否增加.把dis初始化为0,然后转化,如果能增大就更新.每次都判断一下dis[s]. 参考:最快最好用的——spfa算法 代码: #include<cstdio> #include<set> #include<vector> #include<cmath>…
原题链接: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…
Currency Exchange Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1860 Appoint description:  System Crawler  (2015-05-14) Description Several currency exchange points are working in our city. Le…
感觉最短路好神奇呀,刚开始我都 没想到用最短路 题目:http://poj.org/problem?id=1860 题意:有多种从a到b的汇率,在你汇钱的过程中还需要支付手续费,那么你所得的钱是 money=(nowmoney-手续费)*rate,现在问你有v钱,从s开始出发交换钱能不能赚钱 题解:这题其实是用bellman_ford的思想,通过n-1次松弛后,如果还能增加,就说明有环 可以使金钱数不断增加. #include <iostream> #include<cstdio>…
http://poj.org/problem?id=1860 #include <cstdio> //#include <queue> //#include <deque> #include <cstring> using namespace std; #define MAXM 202 #define MAXN 101 int n,m; int first[MAXN]; int next[MAXM]; int pto[MAXM]; double earn[M…
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details/6645778 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <cmat…
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…
题意:有最多一百个房间,房间之间连通,到达另一个房间会消耗能量值或者增加能量值,求是否能从一号房间到达n号房间. 看数据,有定5个房间,下面有5行,第 iii 行代表 iii 号 房间的信息,第一个数字表示从此房间到达连接的房间得到的能量,第二个数字表示连接的有几个房间,后面输出房间后. 思路: 正向去模拟,求出到达n点后尽可能的让dis[n]的值更大 , dis[1]初始化为100,其他初始化为零,因为在松弛的时候必须保证能量值大于零. 这里面说一下SPFA正权回路的判断,当一个点进入队列第n…
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…