poj 1860 Currency Exchange :bellman-ford】的更多相关文章

点击打开链接 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16635   Accepted: 5821 Description Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies…
题目传送门 /* 最短路(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…
原题链接: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…
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…
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 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#problem/A Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16244   Accepted: 5656 Description Several currency exchange point…
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 POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你手中的货币折合成s后是有增加的. 思路: 这道题在建立每种货币的兑换关系后,找到图中的正环即可,因为你沿着正环跑就可以增加价值.这里可以用类似Bellman_Ford判断负环的方法. #include <algorithm> #include <iterator> #include &…
题目链接: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 only with these currencies. There can be several points speci…
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…
Currency Exchange 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/E Description Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operati…
题目链接:http://poj.org/problem?id=1860 题目意思:给出 N 种 currency, M种兑换方式,Nick 拥有的的currency 编号S 以及他的具体的currency(V).M 种兑换方式中每种用6个数描述: A, B, Rab, Cab, Rba, Cba.其中,Rab: 货币A 兑换 货币B 的汇率为Rab,佣金为Cab.Rba:货币B 兑换 货币 A 的汇率,佣金为Cba.假设含有的A货币是x,那么如果兑换成B,得到的货币B 就是:(x-Cab) *…
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…
链接:poj 1860 题意:给定n中货币.以及它们之间的税率.A货币转化为B货币的公式为 B=(V-Cab)*Rab,当中V为A的货币量, 求货币S通过若干此转换,再转换为原本的货币时是否会添加 分析:这个题就是推断是否存在正权回路.能够用bellman-ford算法,只是松弛条件相反 也能够用SPFA算法,推断经过转换后,转换为原本货币的值是否比原值大... bellman-ford    0MS #include<stdio.h> #include<string.h> str…
题目链接: https://cn.vjudge.net/problem/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 only with these currencies. There can be s…
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 o…
题目链接:http://poj.org/problem?id=1860 题意是给你n种货币,下面m种交换的方式,拥有第s种货币V元.问你最后经过任意转换可不可能有升值.下面给你货币u和货币v,r1是u到v的汇率,c1是u到v的手续费,同理r2是v到u的汇率,c2是v到u的手续费.转换后的钱B = (转换之前的钱A - c) * r. 我用spfa做的,不断地松弛.要是存在正环,或者中间过程最初的钱升值了,就说明会升值.有负环的话,不满足松弛的条件,慢慢地就会弹出队列,也就不会升值. #inclu…
感觉最短路好神奇呀,刚开始我都 没想到用最短路 题目: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 找正环,找最长路,水题,WA了两天了.. #include <stdio.h> #include <string.h> struct Edge { int u, v; double r, c; }edge[]; int rear, n, m, s; ]; bool bellman_ford() { memset(dist, , sizeof(dist)); dist[s] = v; ; i < n; i…
传送门:http://poj.org/problem?id=1860 题意:给出每两种货币之间交换的手续费和汇率,求出从当前货币s开始交换回到s,能否使本金增多. 思路:bellman-Ford模板题.直接跑一遍,判断是否存在正环就好了.(复杂度n*m) 代码: #include<iostream> using namespace std; int n; //货币种数 int m; //兑换点数量 int s; //持有第s种货币 double v; //持有的s货币的本金 double di…
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…
题意:有n种货币,可以互相兑换,有m个兑换规则,兑换规则给出汇率r和手续费c,公式为b = (a - c) * r,从a货币兑换为b货币,问能不能通过不断的兑换赚钱,兑换期间手中的钱数不可以为负. 解法:Bellman-Ford.建图:将货币看做点,每种兑换规则为边,两点的路径长度为兑换后的钱数.建图之后可以看出题意为求图中是否存在正环,用Bellman-Ford求最长路径,如果存在正环输出YES,不存在输出NO. 代码: #include<stdio.h> #include<iostr…
题意: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>…
https://vjudge.net/problem/POJ-1860 题意: 有多种货币,可以交换,有汇率并且需要支付手续费,判断是否能通过不断交换使本金变多. 思路: Bellman-Ford算法. 在此之前对贝尔曼-福特算法没怎么了解,当边的权值存在负值的情况下,就可以使用贝尔曼-福特算法. 这个算法主要分为三个部分: 1.首先初始化,和Dijkstra一样,记录原点到各个点的距离,将原点的值设为0,其余点设为无穷大. 2.有n个点的情况下,最多只需要遍历n-1次,每次遍历所有边,进行松弛…
一.题意 有多个货币交易点,每个只能互换两种货币,兑换的汇率不同,并收取相应的手续费.有N种货币,假定你拥有第S中,数量为V,有M个兑换点.问你能不能通过兑换操作使你最后拥有的S币比起始的时候多. 二.题解 货币的交换是可以重复多次的,所以我们需要找出是否存在正权回路(在这一回路上,顶点的权值能不断增加,即能一直进行松弛),且最后得到的s金额是增加的.说到松弛我们立即会想到Bellman-Ford算法,它的特点是可以处理负权边,并能判断是否存在负环(负权回路).本题题恰恰与bellman-For…
( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<vector> #include<queue> using namespace std; ; ; int N,M,S; double V,Vcur[MAXN],R[MAXN][MAXN],C[MAXN][…
套汇问题,从源点做SPFA,如果有一个点入队次数大于v次(v表示点的个数)则图中存在负权回路,能够套汇,如果不存在负权回路,则判断下源点到自身的最长路是否大于自身,使用SPFA时松弛操作需要做调整 #include<iostream> #include<cstdio> #include<string.h> #include <stdlib.h> #include <math.h> using namespace std; const int ma…
真是气skr人..没把d[]换成double...de了一上午的bug// 记得用G++提交啊 题目链接:http://poj.org/problem?id=1860 题意:告诉你n个点,m条路.起始点s,还有初始金额money.每条路表示从a->b的汇率和佣金以及b->a的汇率和佣金.你在该点所得是(本金-佣金)*汇率.问你这个人能不能赚钱. 题解:spfa套一下//.记得d[]换成double.具体的看看代码.QWQ. 代码: #include<iostream> #inclu…