POJ 3259 Wormholes (Bellman_ford算法)】的更多相关文章

http://poj.org/problem?id=3259 农夫john发现了一些虫洞,虫洞是一种在你到达虫洞之前把你送回目的地的一种方式,FJ的每个农场,由n块土地(编号为1-n),M 条路,和W个 虫洞组成,FJ想从一块土地开始,经过若干条路和虫洞,返回到他最初开始走的地方并且时间要在他离开之前,或者恰好等于他离开的时间. 把虫洞的时间看成负边权,就是判断从起点出发是否存在负权回路.那么就可以采用bellman-ford算法,注意数组开大点. /* ********************…
点击打开链接 Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25582   Accepted: 9186 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one…
Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Eac…
版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article/details/37738183 本题事实上也能够使用SPFA算法来求解的,只是就一个关键点,就是当某个顶点入列的次数超过全部顶点的总数的时候,就能够推断是有负环出现了. SPFA原来也是能够处理负环的. 只是SPFA这样的处理负环的方法自然比一般的Bellman Ford算法要慢点了. #inc…
题目传送门 /* 题意:一张有双方向连通和单方向连通的图,单方向的是负权值,问是否能回到过去(权值和为负) Bellman_Ford:循环n-1次松弛操作,再判断是否存在负权回路(因为如果有会一直减下去) 注意:双方向连通要把边起点终点互换后的边加上 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> #…
 POJ 3259 Wormholes Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu   Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way…
POJ 3259 Wormholes(最短路径,求负环) Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE…
题目链接:http://poj.org/problem?id=3259 Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 45077   Accepted: 16625 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is ver…
题意:John的农场里field块地,path条路连接两块地,hole个虫洞,虫洞是一条单向路,不但会把你传送到目的地,而且时间会倒退Ts.我们的任务是知道会不会在从某块地出发后又回来,看到了离开之前的自己. 思路: 这题就是判断存不存在负环回路. 前M条是双向边,后面的W是单向的负边. 为了防止出现不连通,增加一个结点作为起点.起点到所有点的长度为0 #include <iostream> #include <stdio.h> #include <string.h>…
Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24249   Accepted: 8652 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way pa…
题目连接 http://poj.org/problem?id=3259 Wormholes Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a tim…
Wormholes Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3259 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar b…
链接: 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…
Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 41728   Accepted: 15325 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way p…
[原创] 题目大意 John有N个农场,一共有M条边,在农场上出现了W个虫洞(W是一条边),其中M是双向普通边,W是单向虫洞边.John穿行于农场之间每经过一条边(S到E)的时间为+T,每经过虫洞会时间倒流,经过-T.问John会不会在某一刻看到以前的自己.这个题目即问的是,存不存在负权环.bollman_ford 先粘一下百度百科的话: Bellman - ford算法是求含负权图的单源最短路径算法,效率很低,但代码很容易写.其原理为持续地进行松弛(原文是这么写的,为什么要叫松弛,争议很大),…
题意:给出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://poj.org/problem?id=3259 题目: Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 52198   Accepted: 19426 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is…
Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 29971   Accepted: 10844 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way p…
http://poj.org/problem?id=3259 题意 : 农夫约翰农场里发现了很多虫洞,他是个超级冒险迷,想利用虫洞回到过去,看再回来的时候能不能看到没有离开之前的自己,农场里有N块地,M条路连接着两块地,W个虫洞,连接两块地的路是双向的,而虫洞是单向的,去到虫洞之后时间会倒退T秒,如果能遇到离开之前的自己就输出YES,反之就是NO. 样例解释 : 2 3 3 1 1 2 2 1 3 4 2 3 1 3 1 3 3 2 1 1 2 3 2 3 4 3 1 8 第一行中的2代表有两组…
题目:http://poj.org/problem?id=3259 题意:一个famer有一些农场,这些农场里面有一些田地,田地里面有一些虫洞,田地和田地之间有路,虫洞有这样的性质: 时间倒流.问你这个农民能不能看到他自己,也就是说,有没有这样一条路径,能利用虫洞的时间倒流的性质,让这个人能在这个点出发前回去,这样他就是能看到他自己 典型的Bellman_ford 检查有没有形成负环. 套的模板 #include <stdio.h> #include <string.h> ; ;…
http://poj.org/problem?id=3259 题意:有一些普通的洞和虫洞,每个洞都有经过的时间,虫洞的时间是负的,也就是时光倒流,问是否能回到出发时的时间. 思路: 贝尔曼-福特算法判断负环. #include<iostream> #include<algorithm> #include<string> #include<cstring> #include<set> #include<map> using namesp…
题目链接:http://poj.org/problem?id=3259 题目就是问你能否回到原点而且时间还倒回去了.题目中有些路中有单向的虫洞能让时间回到过去 所以只要将虫洞这条边的权值赋为负然后再判断有没有负环就行了. #include <iostream> #include <cstring> using namespace std; const int inf = 10001; int f , n , m , w ,dis[1001] , counts; struct TnT…
Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 34302   Accepted: 12520 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way p…
题目链接:http://poj.org/problem?id=3259 题目大意是给你n个点,m条双向边,w条负权单向边.问你是否有负环(虫洞). 这个就是spfa判负环的模版题,中间的cnt数组就是记录这个点松弛进队的次数,次数超过点的个数的话,就说明存在负环使其不断松弛. #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace st…
/** problem: http://poj.org/problem?id=3259 spfa判负环: 当有个点被松弛了n次,则这个点必定为负环中的一个点(n为点的个数) spfa双端队列优化: 维护队列使其dist小的点优先处理 **/ #include<stdio.h> #include<deque> #include<algorithm> using namespace std; class Graphics{ ; * + ; const static int…
原题链接:http://poj.org/problem?id=3259 题意 有个很厉害的农民,它可以穿越虫洞去他的农场,当然他也可以通过道路,虫洞都是单向的,道路都是双向的,道路会花时间,虫洞会倒退时间,问你这个农民可不可以回到起点,并且在他出发的时间之前. 题解 就虫洞用负边链接,然后判断是否有负环即可. 代码 #include<iostream> #include<cstring> #include<vector> #include<string> #…
Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Eac…
http://poj.org/problem?id=3259 题目大意: 一个农民有农场,上面有一些虫洞和路,走虫洞可以回到 T秒前,而路就和平常的一样啦,需要花费时间走过.问该农民可不可能从某个点出发后回到该点,并且于出发时间之前? 思路: 就是让我们判断存不存在一条总权值未负的回路. 你想想,如果我们一直走这个回路,就可以无限的回到过去.( (╯‵□′)╯︵┻━┻世上哪有时空隧道.想回到过去么?如果可以? 你会去做什么,挽回让自己后悔的事情? ,咳咳,继续题解.) 那就用SPFA呗,如果一个…
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 46123 Accepted: 17033 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path…
Wormholes Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u   Java class name: Main [Submit] [Status] [Discuss] Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A w…