- 博客(10)
- 收藏
- 关注
原创 C++数据结构之栈的实现(顺序栈)
C++数据结构之栈的实现(顺序栈) 首先我们定义了一个栈模板类,它有几个纯虚函数,分别是栈类最常用的几个函数 Push() 将元素放入栈顶 Top() 返回栈顶元素值 Pop() 弹出栈顶元素 Clear() 清空栈(析构函数会用到) 同样我们定义了判断栈是否为空函数IsEmpty(),以及保护成员—栈的高度(长度)height; 模板类定义代码如下 template<class typ...
2020-04-16 19:46:04
846
原创 Dijkstra算法
Dijkstra 算法是对SPFA算法的优化,将普通的队列改为关于距离的优先队列。好处是一旦某个元素出列,这个元素的最短距离已经正确,无需再次入列。 算法描述: 不再将相邻点编号加入队列,而是将相邻点的编号和距离都加入队列,每次出列距离最小的点 模板: #include <bits/stdc++.h> using namespace std; typedef pair<int, ...
2020-02-21 11:43:15
165
原创 SPFA算法实现
SPFA算法是基于拓扑排序的升级版,将边权也考虑在内,SPFA实质是一种基于距离更新+队列的算法。 算法描述:基于拓扑排序稍作改动。从给定起点开始,周围点若距离有更新(变长或变短),就更新距离,若被更新点不在队列里,就把被更新点入列; 代码实现 #include <bits/stdc++.h> using namespace std; typedef long long ll; t...
2020-02-21 10:55:43
403
原创 拓扑排序
拓扑排序是查找有向无环图(DAG)的拓扑序或最长(短)路的一种基本方法,依据BFS思想。 一般模板如下: #include<bits/stdc++.h> using namespace std; int T,n,m,u,v; int deg[100005]; //deg[i]表示i的入度 int vis[100005]; //思考一下,没有vis数组会出现什么问题? vector&...
2020-02-21 09:59:56
146
原创 Weakness and Poorness
Weakness and Poorness You are given a sequence of n integers a1, a2, …, an. Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, …, an - x is as small as possible. The weak...
2020-02-18 12:40:25
222
原创 Multiplication Table
Multiplication Table Bizon the Champion isn’t just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Cha...
2020-02-18 10:03:07
248
原创 Error Curves
Error Curves Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a method called Linear Discriminant Analysis, which has many interesting properties. In or...
2020-02-18 09:47:05
497
原创 Expanding Rods
Expanding Rods When a thin rod of length L is heated n degrees, it expands to a new length L’=(1+n*C)*L, where C is the coefficient of heat expansion. When a thin rod is mounted on two solid walls and...
2020-02-18 09:26:11
137
转载 D - Sand Fortress
D - Sand Fortress You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as ...
2020-02-18 00:24:15
309
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人