线段树(模板1)
摘要:https://www.luogu.com.cn/problem/P3372 push_down把根结点的lazy标记传到其左右子树,并更新左右子树 build递归建立左右子树,到达叶子节点把值赋,遍历后再回溯把左右子树加到根节点上 add 把全覆盖的直接处理,没有全覆盖的就分开递归处理 query
阅读全文
posted @
2022-07-31 23:41
樵风
阅读(20)
推荐(0) 编辑
雷雨(三次diji)
摘要:https://www.luogu.com.cn/problem/P6833 题目的矩阵提供的是点权,预处理每个点与其相邻点建边,边权为终点的点权,链式前向星存边 以题目给的三个点为起点分别跑三次diji 枚举每个点做分叉点,将最小的分叉点到三个点的距离求出来,再减分叉点的点权*2,因为这个点实际求
阅读全文
posted @
2022-07-31 20:36
樵风
阅读(36)
推荐(0) 编辑
LCA(树上倍增)
摘要:https://www.luogu.com.cn/problem/P3379 链式前向星存边 fa[i][j] 代表从i结点向上找 2^i 代的父亲,(i=0代表真父亲) dfs从根结点开始fa[now][i] = fa[fa[now][i - 1]][i - 1];代表当前结点的第2^i代父节点是
阅读全文
posted @
2022-07-31 20:29
樵风
阅读(37)
推荐(0) 编辑
K皇后
摘要:https://www.luogu.com.cn/problem/P2105 遍历行 ,如果发现有标记的就直接下一个 答案先加上这一行所有不可能在逐个减去 遍历所有皇后 lie[queens[q].y]!=i说明此时在同一行 int y = queens[q].x + queens[q].y - i
阅读全文
posted @
2022-07-31 02:09
樵风
阅读(22)
推荐(0) 编辑
KMP
摘要:https://www.luogu.com.cn/problem/P3375 获得next数组(最长公共前后缀) 用类似的方法获得进行kmp操作 每次匹配成功匹配下一个时 有(j=next[j]) #include <bits/stdc++.h> using namespace std; #defi
阅读全文
posted @
2022-07-31 01:48
樵风
阅读(30)
推荐(0) 编辑
矩阵快速幂(运算符重载)
摘要:https://www.luogu.com.cn/problem/P3390 把*重载成矩阵的乘法 再用普通的快速幂就行 (AC代码是copy的,实在debug不出了) #include <algorithm> #include <iostream> #include <cstring> #incl
阅读全文
posted @
2022-07-31 01:39
樵风
阅读(48)
推荐(0) 编辑
混泥土教学(模拟)
摘要:https://www.luogu.com.cn/problem/P6686 记录每个长度的棍子的个数 枚举每个长度,作为腰长 再遍历到腰长两倍以内的,这些累加进去得到满足条件的底的个数 第三步不需要从头遍历,累计的次数k也不需要归0,因为小的腰长对应的底边的个数一定在大的腰长对应底边个数以内,就不
阅读全文
posted @
2022-07-31 01:31
樵风
阅读(26)
推荐(0) 编辑
堆(模板)(优先队列实现)
摘要:P3378 堆好麻烦直接偷懒用优先队列吧 优先小队列(堆顶为最小元)创建priority_queue<int, vector<int>, greater<int>> q; #include <bits/stdc++.h> using namespace std; priority_queue<int
阅读全文
posted @
2022-07-31 01:23
樵风
阅读(17)
推荐(0) 编辑
删数问题(一个数删去几个位上的数后最小)
摘要:https://www.luogu.com.cn/problem/P1106 将字符串中出现递减的数删去(s[i]>s[i+1])此时删去i位置的那个比较大的数 使用erase函数快 循环操作n次结束 #include <bits/stdc++.h> using namespace std; str
阅读全文
posted @
2022-07-31 01:19
樵风
阅读(36)
推荐(0) 编辑
最短路计数(bfs)
摘要:https://www.luogu.com.cn/problem/P1144 邻接矩阵存图 从1出发bfs 同时记录深度 如果下一个点的深度是起点深度+1,那么此刻应该累加路径的条数。 #include <bits/stdc++.h> using namespace std; #define ll
阅读全文
posted @
2022-07-30 23:42
樵风
阅读(55)
推荐(0) 编辑
拆地毯(又是最小生成树)
摘要:https://www.luogu.com.cn/problem/P2121 毫无特色 #include <bits/stdc++.h> using namespace std; #define MAX 10000001 struct node { long long u, v, w; } edge
阅读全文
posted @
2022-07-30 23:37
樵风
阅读(25)
推荐(0) 编辑
修建道路(树状数组,区间修改,单点查询)
摘要:P5019 应用树状数组维护差分数组 遍历数组,找到一个非0的,在从这里往后找到0的,这中间就是区间修改的区间 区间修改的值为这个区间的最小值,在第二步的时候可以顺便记录下来 #include <bits/stdc++.h> using namespace std; #define ll long
阅读全文
posted @
2022-07-30 23:28
樵风
阅读(22)
推荐(0) 编辑
口袋的天空(并查集,生成树)
摘要:P1195 将最小生成树的cnt==n-1改为cnt==n-k即可 还是板子题 #include <bits/stdc++.h> using namespace std; #define MAX 100000000 int n, m, k; struct node { int a, b, c; }
阅读全文
posted @
2022-07-30 23:22
樵风
阅读(47)
推荐(0) 编辑
并查集模板
摘要:P3367 并查集模板。。 #include <bits/stdc++.h> using namespace std; int n, m; #define MAX 1000001 int parent[MAX]; int find(int x) { return (x == parent[x]) ?
阅读全文
posted @
2022-07-30 23:19
樵风
阅读(21)
推荐(0) 编辑
最长公共前后缀
摘要:P2957 数据小直接暴力 遍历字串长度(从大到小),如果满足条件直接输出长度 substr函数使用 #include <bits/stdc++.h> using namespace std; #define MAX 100001 string a, b; int main() { cin >> a
阅读全文
posted @
2022-07-30 23:16
樵风
阅读(40)
推荐(0) 编辑
最小生成树模板题(矩阵输入)
摘要:P1546 无脑最小生成树 矩阵输入 #include <bits/stdc++.h> using namespace std; #define ll long long #define MAX 10000001 int n, k; int parent[MAX]; int idx; struct
阅读全文
posted @
2022-07-30 23:16
樵风
阅读(24)
推荐(0) 编辑
小A的糖果(模拟)
摘要:P3817 模拟,贪心 遍历数组,如果超过了最大糖果数,便修改数组中对应的值并累加 #include <bits/stdc++.h> using namespace std; #define MAX 1000001 long long n, x; long long datas[MAX]; void
阅读全文
posted @
2022-07-30 23:11
樵风
阅读(20)
推荐(0) 编辑