![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
最短路问题
阿聊
愿我千帆过尽,归来仍是少年
展开
-
次短路
找了好半天才找到两个比较好理解的代码,暂时放到这,之后再来改。http://m.blog.csdn.net/spring_3_shine/article/details/56506218#include #include #include #include #include #define INF 0xfffffffusing namespace std;struct原创 2017-11-02 18:44:54 · 197 阅读 · 0 评论 -
hdu2680 choose the best route
题目题意:给定一个有向图,多个起点,一个终点,求起点到终点的最短路。这道题TLE了好多次,两侧次的对比主要在于对起点的处理上,法一:最开始是采用的hdu2066——一个人的旅行,这道题的方法做的,发现总是TLE。法二:然后看别人的博客:再加上一个点作为起点,编号为0,这个点和题中给的那些起点之间的距离为0。这样题目就转化为了求单源最短路径问题。当时我觉得这两种做法没有什么不同,结果...原创 2017-10-28 10:01:11 · 192 阅读 · 0 评论 -
hdu 1874 畅通工程 【spfa and dijkstra实现】
题目spfa: #include <bits/stdc++.h>using namespace std;const int maxn = 205;const int INF = 0x3f3f3f3f;vector <pair<int,int> > E[maxn];int n,m;int d[maxn],inq[maxn];//d[max...原创 2018-08-02 10:50:56 · 114 阅读 · 0 评论 -
最短路 模板 【bellman-ford,dijkstra,floyd-warshall】
Bellman-ford:/*bellman ford*/#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int INF = 0x3f3f3f3f;const int Max = 9999;typedef struct ed...原创 2018-08-02 10:57:16 · 147 阅读 · 0 评论 -
hdu 2066 一个人的旅行
题目分析:题目给定的起点有s个,终点有d个。要求找到从起点到这些终点最短的路径。枚举起点然后比较最后得到最小的值。 #include<stdio.h>#include<iostream>#include<string.h>using namespace std;const int Max = 1010;const int INF = 0x...原创 2017-10-09 15:32:15 · 142 阅读 · 0 评论 -
poj 2449 Remmarguts' Date【第K短路】
题目题意:求 点s 到 点t 的 第 k 短 路的距离;估价函数=当前值+当前位置到终点的距离f(n)=g(n)+h(n); g(n)表示g当前从s到p所走的路径的长度, h(n)‘启发式函数’,表示为终点t到其余一点p的路径长度;(1)将有向图的所有边反向,以原终点t为源点,求解t到所有点的最短距离; (2)新建一个优先队列,将源点s加入到队列中; (3)从...原创 2018-09-16 11:11:52 · 129 阅读 · 0 评论 -
最小生成树练习
poj 2485 题意:给你一个图的邻接矩阵,求最小生成树,输出的是树中的最大边poj 1258题意:和上一题几乎完全相同,求的是最小生成树的总权值hdu 1879 注意:要用scanf();printf() 输入输出,;另外,用kruskal,不能用以顶点为操作对象的prim. ...原创 2018-10-04 17:06:00 · 570 阅读 · 0 评论 -
最小生成树模板
两者的不同之处在于:kruskal----归并边;prim----归并点prim:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int INF = 0x3f3f3f3f;const int Max = 1e3;int mp[...原创 2018-10-04 17:25:21 · 83 阅读 · 0 评论 -
最短路练习
目录最短路练习poj 2387 Til the Cows Come Homepoj 2253 Frogger poj 1797 Heavy Transportationpoj 3268 Silver Cow Partypoj 1860 Currency Exchangehdu 3790 最短路径问题poj 2387 Til the Cows Come Home题...原创 2018-09-29 13:57:31 · 249 阅读 · 0 评论