POJ 3037 SPFA】的更多相关文章

题意: 思路: 我们可以发现 到每个点的速度是一样的 那这就成水题了-. 裸的SPFA跑一哈 搞定 //By SiriusRen #include <cmath> #include <queue> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int v,n,m,map[105][105],xx[]={1,-1,0,0},yy[]={0…
Skiing POJ 3037 很奇怪的最短路问题 题意 题意:你在一个R*C网格的左上角,现在问你从左上角走到右下角需要的最少时间.其中网格中的任意两点的时间花费可以计算出来. 解题思路 这个需要发现一个规律,就是从左上角到其他任意一点,无论选择哪条路径,到达该点的速度都是固定的. 例如对于下面的一个矩阵: 1 5 3 6 3 5 2 4 3 可以发现我们想要计算数值为2的点的速度的话,\[v_2=v_1*2^{1-2}*\],路径是这样的\[1->6->2\], 然后\[v_2=v_1*2…
题目链接: https://cn.vjudge.net/problem/POJ-3037 Bessie and the rest of Farmer John's cows are taking a trip this winter to go skiing. One day Bessie finds herself at the top left corner of an R (1 <= R <= 100) by C (1 <= C <= 100) grid of elevati…
Skiing Bessie and the rest of Farmer John's cows are taking a trip this winter to go skiing. One day Bessie finds herself at the top left corner of an R (1 <= R <= 100) by C (1 <= C <= 100) grid of elevations E (-25 <= E <= 25). In order…
---恢复内容开始--- http://poj.org/problem?id=1511 一个spfa类的模板水题. 题意:就是求从1到n个点的来回的所有距离和. 对spfa类的题还是不太熟练,感觉还是做少了,多水水这种题. 思路:也就是双向的spfa就行了.这里就是注意答案要用long long 类型来存就可以. #include <stdio.h> #include <string.h> #include <queue> #define maxn 1000010 #d…
http://poj.org/problem?id=3268 对于这道题,我想说的就是日了狗了,什么鬼,定义的一个数值的前后顺序不同,一个就TLE,一个就A,还16MS. 感觉人生观都奔溃了,果然,题目做多了总会见到鬼的!!!!!! 心累,不想写这个题了. #include <stdio.h> #include <string.h> #include <queue> #include <iostream> #define inf 0x3f #define M…
题目链接:http://poj.org/problem?id=3268 题意: 有编号为1-N的牛,它们之间存在一些单向的路径.给定一头牛的编号,其他牛要去拜访它并且拜访完之后要返回自己原来的位置,求这些牛中所花的最长的来回时间是多少. 思路: 很骚的写法,这里用了两个数组标记,head,next,他每次找到下一个结点后,head就赋给next了,然后head又是一条新的边,这样,我在遍历这个链表的时候,就能从后往前遍历了,我推了一个小时. 然后这里的if语句也很重要,要先松弛,再看前一个结点有…
题目链接:http://poj.org/problem?id=1511 思路:题目意思很简单就是要求源点到各点的最短路之和,然后再求各点到源点的最短路之和,其实就是建两个图就ok了,其中一个建反图.1000000个点和1000000条边,一开始用SPFA+vector怎么都是TLE,然后换成邻接表就过了=.=. #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #inc…
http://poj.org/problem?id=1511 求解从1去其他顶点的最短距离之和. 加上其他顶点到1的最短距离之和. 边是单向的. 第一种很容易,直接一个最短路, 然后第二个,需要把边反向建一次,跑一个最短路就好. ★.cin  cout 超时 #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #…
题目大意: 计算从 1 点 到 其他所有点的 往返距离之和, 因为是 有向图, 所以我们需要将图反存 一次, 然后求两次单源最短路, 结果就出来了. #include <iostream> #include <cstdlib> #include <cstdio> #include <algorithm> #include <vector> #include <queue> using namespace std; #define IN…