hdu 1932(spfa)】的更多相关文章

XYZZY Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3694   Accepted: 1059 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://acm.hdu.edu.cn/showproblem.php?pid=4568 思路:先用spfa预处理出宝藏与宝藏之间的最短距离,宝藏到边界的最短距离,然后就是经典的求TSP过程了. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; #define M…
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…
这道题是长沙邀请赛的题,当时是道签到题. 这种题还是很常见的,讲一下思路. 首先是预处理出每个宝藏之间的距离,还有到边的距离,直接对每个宝藏进行一次SPFA就可以了. 然后就是经典的求TSP的过程. #include <set> #include <map> #include <stack> #include <cmath> #include <queue> #include <cstdio> #include <string&…
Key Vertex Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1347    Accepted Submission(s): 305 Problem Description You need walking from vertex S to vertex T in a graph. If you remove one vert…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6166 题意:给出一个n个点的有向图.然后给你k个点,求这k个点任意两点之间的最短路的最小值.思路: 以这k个点为起点,维护每个点的最短路和次短路,并且,次短路的祖先不能是本身. 先给几组样例: 55 61 2 1002 5 1005 1 1003 2 1002 4 14 3 121 3 5 61 2 1002 5 1005 1 1003 2 1002 4 14 3 121 3 4 51 3 13 1…
Invitation Cards Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2972    Accepted Submission(s): 1385 Problem Description In the age of television, not many people attend theater performances.…
这题作为模板题,解法好多... 最近周围的人都在搞图论阿,感觉我好辣鸡,只会跟风学习. 暂时只有SPFA和Dijkstra的 SPFA (邻接表版.也可以写成临接矩阵存图,但题目可能给出平行边的,所以要注意找最小的边储存,还要注意判断一个点是否多次进入队列)老实说觉得SPFA好像只是被队列优化过的ford一样的.. #include <stdio.h> #include <algorithm> #include <iostream> #include <strin…
Shopping Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 758    Accepted Submission(s): 254 Problem Description You have just moved into a new apartment and have a long list of items you need t…
最短路径问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 20948    Accepted Submission(s): 6231 Problem Description 给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费,如果最短距离有多条路线,则输出花费最少的.   Inpu…
最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 51083    Accepted Submission(s): 22464 Problem Description 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最…
find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1916    Accepted Submission(s): 668 Problem Description Marica is very angry with Mirko because he found a new g…
Trucking Problem Description A certain local trucking company would like to transport some goods on a cargo truck from one place to another. It is desirable to transport as much goods as possible each trip. Unfortunately, one cannot always use the ro…
Mining Station on the Sea Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2584    Accepted Submission(s): 780 Problem Description The ocean is a treasure house of resources and the development…
题意:有最多一百个房间,房间之间连通,到达另一个房间会消耗能量值或者增加能量值,求是否能从一号房间到达n号房间. 看数据,有定5个房间,下面有5行,第 iii 行代表 iii 号 房间的信息,第一个数字表示从此房间到达连接的房间得到的能量,第二个数字表示连接的有几个房间,后面输出房间后. 思路: 正向去模拟,求出到达n点后尽可能的让dis[n]的值更大 , dis[1]初始化为100,其他初始化为零,因为在松弛的时候必须保证能量值大于零. 这里面说一下SPFA正权回路的判断,当一个点进入队列第n…
http://poj.org/problem?id=1932 spfa求最长路,判断dist[n] > 0,需要注意的是有正环存在,如果有环存在,那么就要判断这个环上的某一点是否能够到达n点,如果能,就说明可以到达,否则,就说明不能. /************************************************************************* > File Name: poj1932.cpp > Author: syhjh > Created…
Floyd Floyd 本质上类似一种动态规划,dp [ i ] [ j ] = dp [ i ] [ k ] + dp[ k ] [ j ]. /** * Night gathers, and now my watch begins. * It shall not end until my death. * I shall take no wife, hold no lands, father no children. * I shall wear no crowns and win no g…
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/2066/ SPFA可以高效过,代码如下: #include<bits/stdc++.h> using namespace std; typedef unsigned int ui; typedef long long ll; typedef unsigned long long ull; #define pf printf #define mem(a,b) memset(a,b,sizeof(a)) #def…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4568 思路:首先spfa预处理出每对宝藏之间的最短距离以及宝藏到边界的最短距离,然后dp[state][u]表示当前在点u,状态为state的最短距离,然后更新就行. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue&g…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4784 思路:建图,对于同一个universe来说,就按题目给的条件相连,对于相邻的universe,连时间花费为1,费用为0的边,需要注意的是,对于起始点和终点只需在universe 0连边就可以了,对于相邻的universe则不需要建边.然后就是跑spfa了,其中dp[u][b][t]表示在顶点u,手中有b袋盐,花费时间为t的最大收益. #include <iostream> #include…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5545 题意:有N个村庄, M 个战场: $ 1 <=N,M <= 10^5 $; 其中曹操会从第i个村庄中选出若个人 在x[i]战场为其作战, 同时第i个村庄也会有相同的人数在y[i]战场为袁绍作战: 每个战场i 有对应的重要度w[i],w[i]的值为 0,1,2: w[i]为2的战场,要求曹操的兵数(从村庄得到的) 严格大于 袁绍的兵的数量: w[i]为1的战场,曹操的兵数不少于袁绍的兵即可:…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1874 spfa 模板 #include<iostream> #include<stdio.h> #include<string.h> #include<queue> using namespace std; <<; ],d[],vis[],n,m; queue<int>q; struct node { int u,v,w,next; } ed…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1535 分析: 题意:求1点到其它点的最短距离之和+其它点到1点的最短距离之和 前面一部分直接用SPFA算法求出,而后一部分可用一数组存放反向边 (所有边的方向都反一下),利用反向边SPFA求出1点到其它点距离即可. #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib>…
题目链接: POJ:http://poj.org/problem?id=3835 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=3268 Problem Description On the evening of 3 August 1492, Christopher Columbus departed from Palos de la Frontera with a few ships, starting a serious of voyages o…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544 Problem Description 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗?   Input 输入包括多组数据.每组数据第一行是两个整数N.M(N<=100,M<=10000),N表示成都的大街上有几个路口,标号为1的路口…
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2680 题目大意,就是一个人可以从多个起点开始出发,看到终点的最短路是多少..只有可以运用和hdu2066一样的思想,对于每个起点可以看成是跟最最开始的点之间有一条权值为0的边.可以把最开始的点记做0点.那这样就可以使用单源最短路了.之前都没有用过spfa,今天来运用了一下. 算法大致流程是用一个队列来进行维护.初始时将源加入队列.每次从队列中取出一个元素,并对所有与他相邻的点进行松弛,若某个相邻的点松…
Bus System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5190    Accepted Submission(s): 1275 [题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=1690 [解题思路]SPFA求最短路径问题,将每个站之间的距离转化为相应的价格从而建立两站点相连的…
POJ 1364 题解:最短路式子:d[v]<=d[u]+w 式子1:sum[a+b+1]−sum[a]>c      —      sum[a]<=sum[a+b+1]−c−1       —      (a+b+1,a) −c−1 式子2:sum[a+b+1]−sum[a]<c      —      sum[a+b+1]<=sum[a]+c−1       —      (a,a+b+1)  c−1 注意:先移项,移项完后再处理没有等于的情况. 附加式:sum[0]&l…
Free DIY Tour Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2735    Accepted Submission(s): 889 [题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=1224 [题目意思]题目是说给你一个有环的图,结点之间有路径,每个结点都有个兴趣值,现在给你起…
http://acm.hdu.edu.cn/showproblem.php?pid=2066 今天复习了一下最短路和最小生成树,发现居然闹了个大笑话-----我居然一直写的是Floyd,但我自己一直以为这是Dijkstra---我居然一直把两个算法 记的是混的,还居然一直没有被别人发现,真是个大乌龙 好了,看看这道题,赤裸裸的最短路水题,首先来个Floyd的,把城市看成点,将连通的的点赋值为给定的时间,未连通的赋值为很大,这是个无向的关系 然后就是三个循环,以一个点为媒介,把每个点遍历一遍,比较…