题意:给出n个房间,初始在房间1有100的能量值,每次进入一个房间,能量值可能增加也可能减小,(是点权,不是边权),问能否到达终点的时候能量值还为正 这题自己写的时候wa--wa-- 后来看了题解,还是wa---wa--- 题解很详细http://blog.csdn.net/freezhanacmore/article/details/9937327 记录下自己犯的错误吧 首先是floyd函数初始化的时候,直接写在了函数里面,这样是不对的,因为输入值在前,调用函数在后,这样就相当于将之前输入的可…
题意:给出n种货币,m中交换关系,给出两种货币汇率和手续费,求能不能通过货币间的兑换使财富增加. 用Bellman_Ford 求出是否有正环,如果有的话就可以无限水松弛,财富可以无限增加. #include<string.h> #include<stdio.h> const int N=110; const int inf=0x3fffffff; int start,num,n; double dist[N],wf; struct edge { int st,ed; double…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1317 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=29015#problem/F XYZZY Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1701    Accepted S…
http://acm.hdu.edu.cn/showproblem.php?pid=1317 题意: 给出一个有向图,每到达一个点,都会加上或减去一些能量,我们要做的就是判断从1出发是否能到达n.初始能量有100,行走的途中能量不能小于等于0. 思路: 首先我们用floyd来判断一下1和n之间是否有通路. 其次就是bellman_ford算法来判正环了. #include <iostream> #include <cstring> #include <algorithm>…
Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你手中的货币折合成s后是有增加的. 思路: 这道题在建立每种货币的兑换关系后,找到图中的正环即可,因为你沿着正环跑就可以增加价值.这里可以用类似Bellman_Ford判断负环的方法. #include <algorithm> #include <iterator> #include &…
题意: 一个图, 点权代表走到该点可获得的能量值. 可正可负. 一个人从1 号出发,带有100点能量. 问是否有一种方案可使人在能量值>0的时候走到n. 思路: 这个题首先要注意点权. 其实就是这点的所有入边的边权都等于这点的点权. 要找长路, 而非最短路. 但是可以借助最短路的算法SPFA求. 最短路的算法SFPA主要是 队列 + 松弛 松弛操作直接关系到我们运行算法的目的----求最短路 如果与该点相邻的下一个点到源的距离可以因为通过该点中转而缩短 ,则更新此下一个点到源的最短距离, 也就相…
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…
传送门:点击打开链接 题目大意:一个城市有n种货币,m个货币交换点,你有v的钱,每个交换点只能交换两种货币,(A换B或者B换A),每一次交换都有独特的汇率和手续费,问你存不存在一种换法使原来的钱更多. 思路:一开始以为一个地方只能用一次,感觉好像有点难,后来发现自己读错题了,其实只要判断给你的这幅图存不存在正环就可以了,用dis[]表示某种货币的数量,然后bellman判断正环就可以了.(题目里强调结尾一定要原来的货币,但其实这是废话,因为是以原来的货币为起点的,所以你换出去了一定换的回来),正…
//spfa 判断正环 #include<iostream> #include<queue> #include<cstring> using namespace std; const int N=1e4; const int INF=2e9; int h[N],to[N],ne[N],idx; double r[N],c[N]; int n, m,X; double V; void add(int u,int v,double r1,double c1) { to[id…
XYZZY Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4421    Accepted Submission(s): 1252 Problem Description It has recently been discovered how to run open-source software on the Y-Crate gami…
XYZZY Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5304    Accepted Submission(s): 1510 Problem Description It has recently been discovered how to run open-source software on the Y-Crate gam…
XYZZY Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4154   Accepted: 1185 Description The prototypical computer adventure game, first designed by Will Crowther on the PDP-10 in the mid-1970s as an attempt at computer-refereed fantasy g…
链接: http://poj.org/problem?id=3259 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#problem/B Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25079   Accepted: 8946 Description While exploring his many farms, Farmer…
题目链接: https://vjudge.net/problem/POJ-1860 题目大意: 我们的城市有几个货币兑换点.让我们假设每一个点都只能兑换专门的两种货币.可以有几个点,专门从事相同货币兑换.每个点都有自己的汇率,外汇汇率的A到B是B的数量你1A.同时各交换点有一些佣金,你要为你的交换操作的总和.在来源货币中总是收取佣金. 例如,如果你想换100美元到俄罗斯卢布兑换点,那里的汇率是29.75,而佣金是0.39,你会得到(100 - 0.39)×29.75=2963.3975卢布. 你…
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…
Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big city! The cows must decide how best to spend their free time. Fortunately, they have a detailed city map showing the L (2 ≤ L ≤ 1000) major landmarks (…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 题目大意:问你是否可以通过转换货币从中获利 如下面这组样例: USDollar 0.5 BritishPound BritishPound 10.0 FrenchFranc FrenchFranc 0.21 USDollar 可以通过US->Br->French->US这样转换,把1美元变成1*0.5*10*0.21=1.05美元赚取%5的利润. 解题思路:其实就相当于bellman-…
题意:给出n个点,m条正权的边,w条负权的边,问是否存在负环 因为Bellman_ford最多松弛n-1次, 因为从起点1终点n最多经过n-2个点,即最多松弛n-1次,如果第n次松弛还能成功的话,则说明存在有负环 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include…
http://acm.hdu.edu.cn/showproblem.php?pid=1317 #include <cstdio> #include <queue> #include <cstring> #include <algorithm> #define maxn 1001 using namespace std; <<; int dis[maxn]; bool vis[maxn]; int n,m,x; int a[maxn]; bool…
题意:John的农场里n块地,m条路连接两块地,k个虫洞,虫洞是一条单向路,不但会把你传送到目的地,而且时间会倒退Ts.我们的任务是知道会不会在从某块地出发后又回来,看到了离开之前的自己. 思路:虫洞连接的边是负权值的,如果途中存在一个负环的话,他可以沿着这个换一直走,时间肯定为负值. #include<string.h> #include<stdio.h> const int N=510; const int inf=0x3fffffff; int start,num,n,dis…
hdu1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4123    Accepted Submission(s): 1878 Problem Description Arbitrage is the use of discrepancies in currency exchange rates to tr…
题目链接: 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…
题目链接:http://poj.org/problem?id=3621 Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11526   Accepted: 3930 Description Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big ci…
链接: 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…
Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16456   Accepted: 5732 Description Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange op…
和POJ1860差不多,就是用bellmanford判读是否存在正环,注意的是同种货币之间也可以交换,就是说:A货币换A货币汇率是2的情况也是存在的. #include<stdio.h> #include<string.h> #include<cstring> #include<string> #include<math.h> #include<queue> #include<algorithm> #include<…
题目链接:http://poj.org/problem?id=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 b…
题意:有m个货币交换点,每个点只能有两种货币的互相交换,且要给佣金,给定一开始的货币类型和货币数量,问若干次交换后能否让钱增加. 思路:spfa求最长路,判断是否存在正环,如果存在则钱可以在环中一直增加,最后的钱肯定也是增加的. #include <iostream> #include <cstring> #include <queue> #include <cstdio> using namespace std; + ; struct edge{ int…
Problem Description It has recently been discovered how to run open-source software on the Y-Crate gaming device. A number of enterprising designers have developed Advent-style games for deployment on the Y-Crate. Your job is to test a number of thes…
两种货币的交换可以当成两条边,建图后跑Bellman_ford算法就好了. Bellman_ford算法可以用来处理负边权,所以可以判断是否存在负环.反过来就可以判断是否存在正环. /*--------------------------------------------------------------------------------------*/ // Helica's header // Second Edition // 2015.11.7 // #include <algor…