随笔分类 -  model

Bellman-Ford
摘要:Acwing模板:https://www.acwing.com/problem/content/855/ 请你求出从 1 号点到 $n$ 号点的最多经过 $k$ 条边的最短距离,如果无法从 1 号点走到 $n$ 号点,输出 impossible。 #include <bits/stdc++.h> u 阅读全文
posted @ 2022-04-17 20:07 Hamine 阅读(52) 评论(0) 推荐(0)
模板查询
摘要:刷题记录:https://www.cnblogs.com/Hamine/p/16030531.html 模板修改记录:https://www.cnblogs.com/Hamine/p/16688792.html - **动态规划** 背包问题:https://www.cnblogs.com/Hami 阅读全文
posted @ 2022-04-17 17:45 Hamine 阅读(412) 评论(0) 推荐(0)
高精度 + 微扰证明
摘要:高精度乘除低精度 + 微扰证明 题目链接: https://www.acwing.com/problem/content/116/ 思路: 通过微扰证明发现所有大臣要按照 $a * b$ 的大小来排序,然后就是高精度的一个乘除了。 代码: #include <bits/stdc++.h> using 阅读全文
posted @ 2022-04-13 15:47 Hamine 阅读(38) 评论(0) 推荐(0)
manacher
摘要:$O(n)$ 时间求出字符串的最长回文子串。 数组 #include <bits/stdc++.h> using namespace std; const int N = 2e7; char s[N << 1], ss[N]; int n, ans, p[N << 1]; void manacher 阅读全文
posted @ 2022-04-05 21:20 Hamine 阅读(67) 评论(0) 推荐(0)
Dijkstra
摘要:求最短路(堆优化) #include <bits/stdc++.h> using namespace std; #define LL long long int main(){ ios::sync_with_stdio(false);cin.tie(0); int n, m; cin >> n >> 阅读全文
posted @ 2022-03-23 23:46 Hamine 阅读(94) 评论(0) 推荐(0)
函数板子
摘要:**exgcd** ``` //给定 a 和 b,求出 x 和 y,使得 a * x + b * y = gcd(a, b) LL exgcd(LL a, LL b, LL &x, LL &y){ if (!b){ x = 1, y = 0; return a; } LL d = exgcd(b, 阅读全文
posted @ 2022-03-17 19:24 Hamine 阅读(87) 评论(0) 推荐(0)
离散化
摘要:离散化 #include <bits/stdc++.h> using namespace std; #define LL long long const int N = 3e5 + 10; LL n, m, a[N], s[N]; int main(){ ios::sync_with_stdio(f 阅读全文
posted @ 2022-03-04 13:40 Hamine 阅读(181) 评论(0) 推荐(0)
kmp
摘要:期望时间复杂度 O(n + m),极限 $O(nm)$。 首先输出若干行,每行一个整数,按从小到大的顺序输出 $s_2$​ 在 $s_1$​ 中出现的位置。 最后一行输出 $\lvert s_2 \rvert$ 个整数,第 $i$ 个整数表示 $s_2$ 的长度为 $i$ 的前缀的最长 $borde 阅读全文
posted @ 2022-03-02 13:07 Hamine 阅读(148) 评论(0) 推荐(0)
主席树(可持久化权值线段树)
摘要:时间复杂度 $O(nlogn)$,建树、查询、修改。 区间第 $k$ 小值。 https://www.luogu.com.cn/problem/P3834 ``` #include using namespace std; using LL = long long; struct President 阅读全文
posted @ 2022-02-27 21:22 Hamine 阅读(86) 评论(0) 推荐(0)
线段树
摘要:查询复杂度:$O(logn)$ **区间修改,区间查询** ``` #include using namespace std; using LL = long long; struct SegmentTree{ struct node{ int l, r; LL sum, add; }; vecto 阅读全文
posted @ 2022-02-27 11:35 Hamine 阅读(94) 评论(0) 推荐(0)
最小生成树(MST)
摘要:Minimum Spanning Tree Prim 在稠密图中比 Kruskal 优,在稀疏图中比 Kruskal 劣。Prim 是以更新过的节点的连边找最小值,Kruskal 是直接将边排序。 Prim 时间复杂度:\(O(n^2)\),通过堆优化可以变成 \(O(mlogn)\) #inclu 阅读全文
posted @ 2022-01-31 14:35 Hamine 阅读(180) 评论(0) 推荐(0)
排序
摘要:1.快速排序 #include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int a[N], n; void quickSort(int l, int r){ int key = a[(l + r) / 2], i = 阅读全文
posted @ 2022-01-13 23:01 Hamine 阅读(127) 评论(0) 推荐(0)
洛谷 P1908 逆序对
摘要:题目链接: https://www.luogu.com.cn/problem/P1908 题目大意: 给长为 n 的序列,求序列中逆序对的数目 思路: 一、 归并: #include <bits/stdc++.h> using namespace std; #define LL long long 阅读全文
posted @ 2022-01-13 16:31 Hamine 阅读(48) 评论(0) 推荐(0)
树状数组
摘要:单点修改,区间查询 #include <bits/stdc++.h> using namespace std; using LL = long long; struct Fenwick{ int n; vector<int> a; Fenwick(int n) : n(n), a(n + 1) {} 阅读全文
posted @ 2022-01-13 12:18 Hamine 阅读(115) 评论(0) 推荐(0)
链式前向星
摘要:head 记录了从每个节点出发的第一条边在 ver 和 edge 数组中的储存位置 ver 记录了每条边的终点 edge 记录每条边的边权 next 模拟了链表指针 //存图 void add(int x, int y, int z){ //x:起点 y:终点 z:权值 ver[++tot] = y 阅读全文
posted @ 2022-01-07 16:47 Hamine 阅读(81) 评论(0) 推荐(0)
并查集(DSU)
摘要:Disjoint Set Union 同时使用了路径压缩 + 启发式合并后,时间复杂度为 $O(\alpha(n))$,阿卡曼反函数 任意一个单独使用,时间复杂度为 $O(nlogn)$ https://www.luogu.com.cn/problem/P3367 #include<bits/std 阅读全文
posted @ 2021-12-16 10:01 Hamine 阅读(72) 评论(0) 推荐(0)
欧几里得算法及扩展
摘要:noj:http://39.98.219.132:8080/problem/208 #include <bits/stdc++.h> using namespace std; #define LL long long LL gcd(LL a, LL b){ return (a % b == 0) ? 阅读全文
posted @ 2021-11-15 20:03 Hamine 阅读(85) 评论(0) 推荐(0)
背包问题
摘要:一、01背包 有 $n$ 件物品和一个容量为 $W$ 的背包,第 $i$ 件物品的体积为 $w[i]$,价值为 $v[i]$,求解将哪些物品装入背包中使总价值最大。 例:https://www.acwing.com/problem/content/2/ 思路: 当放入一个价值为 $w[i]$ 的物品 阅读全文
posted @ 2021-11-13 12:58 Hamine 阅读(184) 评论(0) 推荐(0)
最长公共子序列
摘要:简单,数据为 1e3 #include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; char a[N], b[N]; int n, m, f[N][N]; void solve(){ cin >> n >> m >> a 阅读全文
posted @ 2021-11-01 09:34 Hamine 阅读(77) 评论(0) 推荐(0)
欧拉筛
摘要:luogu:https://www.luogu.com.cn/problem/P3383 acwing:https://www.acwing.com/problem/content/870/ #include <bits/stdc++.h> using namespace std; const in 阅读全文
posted @ 2021-10-13 13:15 Hamine 阅读(40) 评论(0) 推荐(0)