
最短路径
小魚兒.
天下皆白,唯我独黑!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
10.4.3 全源最短路径——Floyd算法
#include <cstdio>#include <algorithm>using namespace std;//Floyd 算法——全源最短路径//伪代码/*枚举顶点k∈[1,n] 以顶点k作为中介点,枚举所有顶点对i和j(i∈[1,n],j∈[1,n] ) 如果dis[i][k]+dis[k][j]<dis[i][j]成立 //找到以k为中...原创 2019-11-06 15:04:36 · 213 阅读 · 0 评论 -
SPFA算法——优化后的Bellman算法
#include <cstdio>#include <queue>#include <vector>using namespace std;//优化后的Bellman算法——SPFA//1、伪代码queue <int> q;q.push(s) ;//源点s入队while(!q.empty()) //队列非空{ int u=q...原创 2019-11-06 14:38:57 · 151 阅读 · 0 评论 -
10.4 PAT A1003 Emergency (25 分)(最短路径及最大点权——Bellman算法实现)
1003 Emergency (25 分)As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams...原创 2019-11-05 15:24:19 · 233 阅读 · 0 评论 -
10.4 Bellman-Ford 算法求最短路径(可求解负权值)(基础算法)
//Bellman-Ford 算法求最短路径(可求解负权值)//伪代码for(int i=0;i<n-1;++i) //执行n-1轮操作 { for(each edge u->v) { if(d[u]+length[u->v]<d[v]) //以u为中介点可以使d[v]更小 d[v]=d[u]+length[u->v]; //松弛操作 }...原创 2019-11-05 14:55:06 · 171 阅读 · 0 评论 -
PAT 10.4 A 1030 Travel Plan (30 分)(最短路径及最小花费——Dijkstra算法)
1030 Travel Plan (30 分)A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to d...原创 2019-11-03 15:55:24 · 195 阅读 · 0 评论 -
最短路径第二尺度求解优化算法(Dijkstra+DSF)
#include <cstdio>#include <cstring> #include <algorithm>#include <vector>using namespace std;const int maxv=520;const int INF=1000000000;//利用pre数组先求出每个点的点权或边权之和的模板。可直...原创 2019-11-02 16:04:42 · 416 阅读 · 0 评论 -
PAT A 1003 Emergency (25 分)(图的最短路径条数及最大点权)(Dijkstra算法)
1003 Emergency (25 分)As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams...原创 2019-11-02 15:20:52 · 195 阅读 · 1 评论 -
10.4 最短路径(黑暗大陆——亚历山大)
#include <cstdio>#include <algorithm>using namespace std;const int maxv=1122;const int INF=1000000000;int n,m,s,G[maxv][maxv];int d[maxv];bool vis[maxv]={false};void Dijkstra(int...原创 2019-10-30 15:28:00 · 112 阅读 · 0 评论 -
10.4 最短路径相关算法——点权、边权、最短路径条数(基础算法)
#include <cstdio>#include <vector>using namespace std;//单源最短路径——Dijkstra算法//1、伪代码//G为图,一般设成全局变量 ,数组d为源点到达各点的最短路径长度/*Dijstra(G,d[],s){ 初始化; for(循环n次) { u=使d[u]最小的还未被访问的顶点的标号 ...原创 2019-10-30 15:07:13 · 1943 阅读 · 0 评论