POJ - 3037 Skiing SPFA】的更多相关文章

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…
题目链接: 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 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4810   Accepted: 1287   Special Judge Description 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 c…
Skiing Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4668   Accepted: 1242   Special Judge Description 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 c…
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…
题意: 思路: 我们可以发现 到每个点的速度是一样的 那这就成水题了-. 裸的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…
http://poj.org/problem?id=1860 题意:汇率转换,与之前的2240有点类似,不同的是那个题它去换钱的时候,是不需要手续费的,这个题是需要手续费的,这是个很大的不同. 思路:还是转换成为最短路的问题,主要的困难也就是关于它的松弛方程.dist [edge[i].v] < (dist[ tmp ] - edge[ i ].r) * edge[ i ].c  .这个就是松弛方程,当它的钱的数目增多的时候松弛. #include <stdio.h> #include…
http://poj.org/problem?id=3621 求一个环的{点权和}除以{边权和},使得那个环在所有环中{点权和}除以{边权和}最大. 0/1整数划分问题 令在一个环里,点权为v[i],对应的边权为e[i],  即要求:∑(i=1,n)v[i]/∑(i=1,n)e[i]最大的环(n为环的点数),  设题目答案为ans,  即对于所有的环都有 ∑(i=1,n)(v[i])/∑(i=1,n)(e[i])<=ans  变形得ans* ∑(i=1,n)(e[i])>=∑(i=1,n)(v…
http://poj.org/problem?id=1847 一个水题,用来熟悉熟悉spfa和floyd的. 题意:有m条的铁路,要从x,到y, 之后分别就是条铁路与其他铁路的交点.第一个输入的为有n个交点.之后第一个输入的点,当前铁路到这个点是不要转向的,也就是权值为0,其余的权值都为1,求从x到y的最短路,如果到不了输出-1 裸的floyd和spfa: #include <stdio.h> #include <string.h> #define inf 0x3f3f ][];…
 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…
题目链接:http://poj.org/problem?id=3259 Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 44090   Accepted: 16203 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is ver…
题目链接:http://poj.org/problem?id=1511 嗯,最后一次写SPFA了,以后就套模板了. 题意:给出n个点和n条有向边,求所有点到源点1的来回最短路之和(保证每个点都可以往返源点1). 思路:建反图,从任意一点回来,就变成了反图上的从1到任意一点去. next记录前驱,head[u],记录u是在第几条边,然后往前扫.例如:edge[0].next = head[1] =0;head[1] = 0;edge[3].next = head[1] =0;head[1] =3;…
题目链接:http://poj.org/problem?id=2679 嗯,思路清晰,先DFS看是不是通路,接着就是SPFA找最短路(路是费用,费用相同就比较路的长度). 超哥的代码还有一点问题,初始化最小费用为0,也能AC,我不信,if语句也好像写错了,只能说明这个题目数据水. #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<queu…
http://poj.org/problem?id=3259 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 BEFOR…
题目链接:http://poj.org/problem?id=3169 差分约束的解释:http://www.cnblogs.com/void/archive/2011/08/26/2153928.html 我也不是特别理解,要是给你a - b <= k 就建一条b->a权值为k的有向边,要是a - b >= k 就建一条a -> b边权是-k的有向边,要是让你求n到1的最大差,就是让你求1到n的最短距离. 差分约束系统有两种方式可以求解,最短路和最长路.当我们把不等式整理成d[a…
题目链接:http://poj.org/problem?id=3259 题目大意是给你n个点,m条双向边,w条负权单向边.问你是否有负环(虫洞). 这个就是spfa判负环的模版题,中间的cnt数组就是记录这个点松弛进队的次数,次数超过点的个数的话,就说明存在负环使其不断松弛. #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace st…
点击打开链接 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…
A*算法求第k短路流程: 1)计算h[],即当前点到t的估计值 若为有向图,建立反向图求出h[].若为无向图,可直接求解h[].可通过SPFA求解. 2)A*搜索 每次找到新节点就直接加入队列,计算出估价函数f[]=g[]+h[],然后加入优先队列中.(此步不可优化,否则可能造成失解) 常用STL priority_queue实现,要注意默认是大根堆,可重载<实现小根堆. 3)若根入队k次,返回 ADD: 该题几个注意事项及优化: a)若起始点h值==INF,不搜. b)若一个点入队超过k次,不…
d[i]代表从起点出发可以获得最多的钱数,松弛是d[v]=r*d[u],求最长路,看有没有正环 然后这题输入有毒,千万别用cin 因为是大输入,组数比较多,然后找字符串用strcmp就好,千万不要用map 这题刚开始我T了(用的map),还以为组数很多卡spfa呢,然后我上网看了看都是floyd的,然后我用floyd写了一发,891ms过了 然后我感觉spfa的复杂度也不是很大,就是看有没有正环,所以我觉得可能是map+cin的锅,然后改了一发,用的spfa,47ms过 真是,算了,实质是本蒟蒻…
题意:给出一个有向图,问求一个回路,使得回路上的点权之和/边权之和最大. 这题主要是分析出如何确定ans值.我们将(a1*x1+a2*x2+..+an*xn)/(b1*x1+b2*x2+..+bn*xn)=L,转换为:x1*(a1-b1*L)+x2*(a2-b2*L)+...xn*(an-bn*L)=0 则每次枚举L的值,spfa中边权值为len[]*L-a[],若存在负环回路(即一个点访问次数超过n次)则表示L的值小了,增大L值;反之减小L值. 代码: #include<iostream>…
Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 49962   Accepted: 18421 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…
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…
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…
题意 有多种汇币,汇币之间可以交换,这需要手续费,当你用100A币交换B币时,A到B的汇率是29.75,手续费是0.39,那么你可以得到(100 - 0.39) * 29.75 = 2963.3975 B币.问s币的金额经过交换最终得到的s币金额数能否增加 货币的交换是可以重复多次的,所以我们需要找出是否存在正权回路,且最后得到的s金额是增加的 怎么找正权回路呢?(正权回路:在这一回路上,顶点的权值能不断增加即能一直进行松弛) Sample Input 3 2 1 20.0 1 2 1.00 1…
版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article/details/37738183 本题事实上也能够使用SPFA算法来求解的,只是就一个关键点,就是当某个顶点入列的次数超过全部顶点的总数的时候,就能够推断是有负环出现了. SPFA原来也是能够处理负环的. 只是SPFA这样的处理负环的方法自然比一般的Bellman Ford算法要慢点了. #inc…
题意 : 给出 N 个点,以及 M 条双向路,每一条路的权值代表你在这条路上到达终点需要那么时间,接下来给出 W 个虫洞,虫洞给出的形式为 A B C 代表能将你从 A 送到 B 点,并且回到 C 个时间点之前,也就是时光倒流了 C 个时间并且此时你在 B 点,现在问你是否能够在图上的这些点中走,使得在某一个点刚好碰到之前的自己 分析 : 冷静分析一下,只要是有负权回路的某一条边属于虫洞的,那么肯定是能在这个环上一直绕,直到遇到之前的自己,如果将虫洞看作一条负权边的话,那么问题就变成了只要存在负…
Arbitrage Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound, 1 British pound buys 10.0 Frenc…
Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5769    Accepted Submission(s): 2316 Problem Description Although winter is far away, squirrels have to work day and night to save b…
poj——3037 Skiing Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4921   Accepted: 1315   Special Judge Description 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…
先简单介绍一下最短路径: 最短路径是啥?就是一个带边值的图中从某一个顶点到另外一个顶点的最短路径. 官方定义:对于内网图而言,最短路径是指两顶点之间经过的边上权值之和最小的路径. 并且我们称路径上的第一个顶点为源点,最后一个顶点为终点. 由于非内网图没有边上的权值,所谓的最短路径其实是指两顶点之间经过的边数最少的路径. 我们时常会面临着对路径选择的决策问题,例如在中国的一些一线城市如北京.上海.广州.深圳等,一般从A点到到达B点都要通过几次地铁.公交的换乘才可以到达. 有些朋友想用最短对的时间,…