随笔分类 - 基础数据结构
摘要:#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 20; int son[N * 31][2], cnt[N * 31]; int idx; void insert(int x) { int p = 0; for(in
阅读全文
摘要:Sparse Table Sparse Table是一种简单的离线数据结构,主要用于解决RMQ(Range Maximum/Minimum Query, 区间最值查询)问题。它主要应用倍增的思想,可以实现 \(O(nlogn)\) 预处理、 \(O(1)\) 查询。 ST使用一个二维数组 \(f\)
阅读全文
摘要:树状数组复习 1. 楼兰图腾: 区间查询 对于 v : 统计左侧有多少个大于x的,右侧有多少个大于x的, 两者相乘 对于 ^ : 统计左侧有多少个小于x的,右侧有多少个小于x的, 两者相乘 对于每一个加入的数,相当于给那个值的位置+1 每一次统计:[1,v] [v,+inf] 个数 #include
阅读全文
摘要:除留余数法 \(H(key) = key \ \ MOD\ \ p\ \ (p \leq m)\) 处理冲突(探测)方法: 线性探测再散裂 再哈希法(多次哈希) 链地址法 查找成功的平均查找长度: (每次查找至查找成功的次数之和) / 查找次数 装填因子$\alpha = \frac{表中填入的记录
阅读全文
摘要:1.Prim 2.Kruscal 3.Dijkstra 4.Floyd 5.Topological sorting
阅读全文
摘要:[模板] fhq Treap (无旋Treap) 模板题AcWing253.普通平衡树 教程视频 #include <cstdio> #include <algorithm> #include <queue> using namespace std; const int N = 1e5+5; str
阅读全文
摘要:1.字符串统计 用vector来优化时间和空间,idx为索引 #include <cstdio> #include <cstring> #include <vector> #include <cstdlib> using namespace std; const int N = 2e5+5; int
阅读全文
摘要:树状数组 前置知识: lowbit 函数 lowbit函数用于求一个非负整数n在二进制表示下最低位1及其后面的0所构成的数值 Decimal Binary Lowbit(Binary) Lowbit(Decimal) 1 001 1 1 3 011 1 1 4 100 100 4 8 1000 10
阅读全文
摘要:稀疏矩阵运算 在实现的过程中,避免使用C++的高级容器. #include <iostream> #include <cstdlib> using namespace std; class Node{ public: int row; int col; int value; Node(){}; No
阅读全文
摘要:C.Cover the Tree 题解 题目链接 https://ac.nowcoder.com/acm/contest/5667/C 当做结论记下来好了。用最少条链来覆盖一棵树的时候,最优解为 s / 2 上取整. 方法为先找到一个非叶节点(度>=2)作为根(对于无根树),然后dfs找出所有的叶节
阅读全文
摘要:1 #include <iostream> 2 #define black 'f' 3 #define white 'e' 4 #define grey 'p' 5 using namespace std; 6 struct node{ 7 char type; 8 node* upper_r; 9
阅读全文
摘要:为什么这个题网上全是用指针建树呢? 虽然刘爷的紫书上标程拿指针写,不过明显这题有更加简单的写法。 根据输入的每个节点的生成路径判断其对应完全二叉树时的编号。 设根节点为1号,左儿子编号为 id << 1 , 右儿子编号为 id << 1 | 1 按照编号大小排序,顺序输出就是层次遍历。 如何判断是否
阅读全文
摘要:题目链接:https://vjudge.net/problem/UVA-514 思路: 用两个指针 A , B 分别表示 ' 理论上驶出车站的车厢 ' 、 ' 实际上驶出车站的车厢 ' 用循环、栈模拟 (是的这就是刘哥的代码) 1 #include <cstdio> 2 #include <stac
阅读全文
摘要:单调队列是一种操作受限的数据结构 只允许从队首出队、队首和队尾入队。 它可以用于维护区间内的最大值和最小值。 性质: 1.单调队列内的所有元素的相对位置和原列表中相同。 2.队首的元素根据需要,一定是最大(或最小的)。 3.队首的元素一定是最先入队的,队尾的元素是走后入队的。 4.队列中的元素保持着
阅读全文
摘要:今天刚刚学习堆和堆排,先手抄了一遍算法书,再自己实现一遍,作为巩固。 update : 早上起床把小根堆写了一遍 = 。 = 1 /* 小根堆 */ 2 #include <iostream> 3 #include <vector> 4 using namespace std; 5 void dow
阅读全文