03 2022 档案
摘要:
#单源最短路 ##正权边 ###Dijkstra算法 O(n^2) 每次通过已知最短距离来更新到其他点的最短路 注意出现重边要进行比较 #include<iostream> #include<algorithm> using namespace std; const int N = 1e5+10;
阅读全文

摘要:
##拓扑排序 前提是有向无环图,是图的宽度优先搜索的应用 拓扑序列 若一个由图所有点构成的序列A满足,对于图的每条边(x,y),x在A中的出现,都在y的前面,则称A是这个图的拓扑排序 bool topsort() { int hh = 0, tt = -1; // d[i] 存储点i的入度 for
阅读全文

摘要:
##数组实现最小堆 // h[N]存储堆中的值, h[1]是堆顶,x的左儿子是2x, 右儿子是2x + 1 // ph[k]存储第k个插入的点在堆中的位置 // hp[k]存储堆中下标是k的点是第几个插入的 int h[N], ph[N], hp[N], size; // 交换两个点,及其映射关系
阅读全文

摘要:
##KMP 记忆化搜索,ne用来记录最大前后缀 // s[]是长文本,p[]是模式串,n是s的长度,m是p的长度 #include <iostream> using namespace std; const int N = 1e5 + 10; char s[N], p[N]; int ne[N];
阅读全文

摘要:
##问题描述 约瑟夫问题是个著名的问题:N个人围成一圈,第一个人从1开始报数,报M的将被杀掉,下一个人接着从1开始报。如此反复,最后剩下一个,求最后的胜利者。 ##解决方式 1.数组模拟 2.递归处理 3.公式法 模拟 #include <iostream> using namespace std;
阅读全文

摘要:
##链表 ###单链表 例题 算法题中用数组实现链表,时间费用低 // head存储链表头,e[]存储节点的值,ne[]存储节点的next指针,idx表示当前用到了哪个节点 int head, e[N], ne[N], idx; // 初始化 void init() { head = -1; idx
阅读全文

摘要:
##双指针 时间复杂度普遍为O(n) for (int i = 0, j = 0; i < n; i ++ ) { while (j < i && check(i, j)) j ++ ; // 具体问题的逻辑 } 例题 #include <iostream> #include <cstring> #
阅读全文

摘要:
##一维前缀和 例题 #include<iostream> using namespace std; const int N = 1e5+10; int n,m; int s[N],num[N]; int main() { cin >> n >> m; for(int i = 1; i <= n;
阅读全文

摘要:
##高精度加法 #include <iostream> #include <vector> #include <cstring> using namespace std; vector<int> add(vector<int> &A, vector<int> &B) { vector<int> C;
阅读全文
