随笔分类 - model
博弈论
摘要:公平组合游戏: 1.由两名玩家交替行动; 2.在游戏进程的任意时刻,可以执行的合法行动与轮到哪名玩家无关; 3.不能行动的玩家判负; 有向图游戏:给定一个有向无环图,图中有一个唯一的起点,在起点上放有一枚棋子。两名玩家交替地把这枚棋子沿有向边进行移动,每次可以移动一步,无法移动者判负。 任何一个公平
阅读全文
卡特兰数
摘要:给定 \(n\) 个 0 和 \(n\) 个 1,它们按照某种顺序排成长度为 \(2n\) 的序列,满足任意前缀中 0 的个数都不少于 1 的个数的序列的数量为:\(Cat(n) = C_{2n}^n - C_{2n}^{n - 1} = \frac{C_{2n}^n}{n + 1}\) #incl
阅读全文
Lucas定理
摘要:acwing:https://www.acwing.com/problem/content/889/ \(C_a^b \equiv C_{a \% p}^{b \% p}\) * $C_{\frac{a}{p}}^{\frac{b}{p}} (mod p) $ #include <bits/stdc
阅读全文
高斯消元
摘要:acwing:https://www.acwing.com/problem/content/885/ 高斯消元求解线性方程组 #include <bits/stdc++.h> using namespace std; #define LL long long const int N = 110; c
阅读全文
逆元
摘要:acwing:https://www.acwing.com/problem/content/878/ 求逆元 #include <bits/stdc++.h> using namespace std; #define LL long long LL n, a, p; LL qp(LL a, LL k
阅读全文
裴蜀定理
摘要:裴蜀定理内容:\(ax+by=c\), \(x \in Z^∗\), \(y \in Z^∗\) 成立的充要条件是 \(gcd(a, b) ∣ c\)。\(Z^*\) 表示正整数集。 luogu:https://www.luogu.com.cn/problem/P4549 给定一个序列 \(a\)
阅读全文
三分
摘要:luogu:https://www.luogu.com.cn/problem/P3382 给出一个 \(n\) 次函数,保证在范围 \([l, r]\) 内存在一点 \(x\),使得 \([l, x]\) 上单调增,\([x, r]\) 上单调减。求出 \(x\) 的值。 #include <bit
阅读全文
欧拉函数
摘要:欧拉函数的值:1 到 $n$ 中与 $n$ 互质的数的个数。 性质: 1.$\sum_{d | n} \phi(d) = n$ 证明:https://blog.csdn.net/Morning_Glory_JR/article/details/94155283 欧拉反演: $\sum_{i = 1}
阅读全文
最近公共祖先(LCA)
摘要:luogu 模板:https://www.luogu.com.cn/problem/P3379 树剖求 $LCA$ 时间复杂度 $O(2n + qlogn)$ #include<bits/stdc++.h> using namespace std; using LL = long long; str
阅读全文
树的重心
摘要:https://www.acwing.com/problem/content/848/ 输出将重心删除后,剩余各个连通块中点数的最大值。 时间复杂度:$O(n)$,极限 $O(n^2)$ #include <bits/stdc++.h> using namespace std; const int
阅读全文
字典树(trie)
摘要:acwing: https://www.acwing.com/problem/content/837/ 在集合中插入字符串,询问字符串在集合中出现了多少次。 #include <bits/stdc++.h> using namespace std; #define LL long long cons
阅读全文
单调队列
摘要:luogu: https://www.luogu.com.cn/problem/P1886 #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int n, k, a[N]; void getMin(){ vec
阅读全文
字符串哈希
摘要:acwing: https://www.acwing.com/problem/content/843/ 包含大小写英文字母和数字的字符串中,问某两段区间的字符串是不是相同的 #include <bits/stdc++.h> using namespace std; #define ULL unsig
阅读全文
矩阵快速幂及应用
摘要:luogu 模板: https://www.luogu.com.cn/problem/P3390 矩阵快速幂 #include <bits/stdc++.h> using namespace std; #define LL long long const int N = 110, mod = 1e9
阅读全文
单调栈
摘要:#include <bits/stdc++.h> using namespace std; int n; int main(){ ios::sync_with_stdio(false);cin.tie(0); cin >> n; vector <int> a(n), f(n); for (int i
阅读全文
ST表
摘要:luogu 模板: https://www.luogu.com.cn/problem/P3865 静态区间最大值查询 #include <bits/stdc++.h> using namespace std; using LL = long long; //mx[i][j] 表示从第 i 个位置开始
阅读全文
二分图
摘要:二分图:将图中所有点分成两个集合,所有边只会出现在集合之间。 二分图一定不含奇数环 染色法判断二分图 #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, m, color[N]; vector <i
阅读全文
Floyd
摘要:#include <bits/stdc++.h> using namespace std; const int N = 210, INF = 0x3f3f3f3f; int d[N][N], n, m, q; void Floyd(){ for (int k = 1; k <= n; k ++ )
阅读全文
SPFA
摘要:求最短路 #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, INF = 0x3f3f3f3f; int n, m, d[N]; bool st[N]; vector < pair<int, int> > g[N
阅读全文
数位dp
摘要:题目链接: https://www.luogu.com.cn/problem/P2602 https://www.acwing.com/problem/content/340/ 题目大意: 计算 $a$ 到 $b$ 区间中每一个数码出现的次数。 思路: 记忆化搜索 #include <bits/st
阅读全文
浙公网安备 33010602011771号