图论
Haskei
这个作者很懒,什么都没留下…
展开
-
只有五行的算法--Floyd-Warsha
告诉你各个城市之间的距离,让你求从某个城市到另一个城市的最短路径问题因为从一个城市到另一个城市想要缩短距离,只能经过其他城市来缩短距离#include #include #include #include #include #include #include #include #include #define INF 99999原创 2016-11-04 20:27:34 · 915 阅读 · 0 评论 -
最小生成树
1.Kruskal算法首先按照变得权值从小到大排序,每次从剩余的边中选出权值最小的且两个顶点不在同一集合中的边(为的是不产生回路),加入到生成树中,直到加入了n-1条边为止对边进行快排O(MkogM),在m条边中选出n-1条边是O(MlogN),所以Kruskal算法的时间复杂度为O(MlogM +MlogN),通常M要比N大得多,因此最终算法的时间复杂度为O(MlogM)#inc原创 2016-11-10 20:34:15 · 389 阅读 · 0 评论 -
POJ 1703 Find them, Catch them 种类并查集
Find them, Catch themTime Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %lluSubmit Status Practice POJ 1703DescriptionThe police office in Tadu City decides原创 2016-11-22 17:25:20 · 371 阅读 · 0 评论 -
Socks CF 731C 并查集
SocksTime Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64uSubmit Status Practice CodeForces 731CDescriptionArseniy is already grown-up and independent.原创 2016-11-22 21:43:29 · 922 阅读 · 0 评论 -
Til the Cows Come Home 最短路径
Til the Cows Come HomeTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionBessie is out in the field and wants to get back to the ba原创 2016-11-24 15:48:57 · 413 阅读 · 0 评论 -
Slim Span 求生成树的最大边与最小边的差最小的值
Slim SpanTime Limit:5000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit Status Practice POJ 3522DescriptionGiven an undirected weighted graph G, you should原创 2016-11-21 20:52:49 · 1127 阅读 · 0 评论 -
单源最短路径 Bellman-Ford----解决负权变(加入了队列优化)
算法过程初始时将源点加入队列,每次从队首取出一个定点,并与其出边进行松弛操作,如果松弛成功则将该出边的终点加入到队列中去,处理完毕该点的所有出边后,出队列,继续进行上述操作,选取队列的顶点,直到队列为空,算法结束,这里需要用一个book数组进行记录目前队列中存在哪些点,如果对某一条边松弛成功,但是该出边的终点在队列中,那么久没必要把该点插入到队列中,因为队列中存在该点,会对该点的说=所有出边进原创 2016-11-13 19:50:31 · 496 阅读 · 0 评论 -
Borg Maze 广搜+最小生成树
Borg MazeTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionThe Borg is an immensely powerful race of enhanced humanoids from the d原创 2016-11-20 16:20:50 · 412 阅读 · 0 评论 -
Truck History 最小生成树
Truck HistoryTime Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionAdvanced Cargo Movement, Ltd. uses trucks of different types. Some原创 2016-11-19 16:12:06 · 463 阅读 · 0 评论 -
The Unique MST 独一无二的最小生成树
The Unique MSTTime Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionGiven a connected undirected graph, tell if its minimum spanning t原创 2016-11-19 15:36:31 · 364 阅读 · 0 评论 -
The Suspects 解决多棵树合并成一棵树的问题
The SuspectsTime Limit:1000MS Memory Limit:20000KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionSevere acute respiratory syndrome (SARS), an atypical pneumonia of u原创 2016-11-18 10:45:01 · 1231 阅读 · 0 评论 -
Conscription 征兵
ConscriptionTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionWindy has a country, and he wants to build an army to protect his原创 2016-11-17 15:54:19 · 446 阅读 · 0 评论 -
Fix a Tree 利用并查集合并树,解决树中存在环的问题
Fix a TreeTime Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64uSubmit StatusDescriptionA tree is an undirected connected graph without cycles.Let's cons原创 2016-11-16 19:58:04 · 514 阅读 · 0 评论 -
Prime算法 与 Kruskal算法的时间复杂度比较
转自G机器猫评测环境:WindowsXP,FreePascal2.40,Pentium(R) Dual-Core CPU T4300@2.10GHz,2G内存通过上图可以看出:1.Prim在稠密图中比Kruskal优,在稀疏图中比Kruskal劣。2.Prim+Heap在任何时候都有令人满意的的时间复杂度,但是代价是空间消转载 2016-11-11 20:23:48 · 16969 阅读 · 1 评论 -
图的存储结构
1.邻接矩阵用一个n×n的二维数组来存储,例如node[i][j],代表的是从点i到点j的距离为node[i][j],缺点是无法存储重边的情况,比如从i点到j点有两条路可以走,一条路的长度为3,一条路的长度为5代码实现 int n,m,node; scanf("%d%d",&n,&m);//n点的个数,m边的条数 //建立城市之前的关系原创 2016-11-06 21:56:42 · 362 阅读 · 0 评论 -
并查集
并查集分两部分,并和查,把相同祖先的人并到一起,查是检查两个人是否是同一个祖先,并查集与邻接表有些相似,但是邻接表是没办法通过直接通过起点和终点确定,两个点之间是否有边,其实也就是表达的并查集当中的两个人是否与共同的祖先#include#include#include#include#include#include#include#define maxn 20#define i原创 2016-11-10 00:27:57 · 310 阅读 · 0 评论 -
单源最短路径 -- Dijkstra算法
求一个点(源点)到其余点的最短路径问题,利用f数组记录该节点的父节点,以便以后打印路经的时候,倒着回去的时候打印路径#include<iostream> //没有利用邻接表存储图形结构的算法,该种方法存储图的空间复杂度为O(n*n),遍历每一条边的时间复杂度为O(m)#include<cstdio> //算法的时间复杂度为O(n...原创 2016-11-04 21:26:20 · 557 阅读 · 0 评论