![](https://img-blog.csdnimg.cn/20190918140145169.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
模板
.
EHWWFFT.
这个作者很懒,什么都没留下…
展开
-
fft模板+讲解
讲解:https://blog.csdn.net/qq_37136305/article/details/81184873 有点小问题,一个是代码不太对,另一个是倍增的图不太对。讲解+代码:https://www.cnblogs.com/zwfymqz/p/8244902.html。原创 2022-11-11 19:49:46 · 142 阅读 · 1 评论 -
Tarjan算法模板+讲解(邻接表) 求强连通分量
讲解:https://blog.csdn.net/hurmishine/article/details/75248876#include <bits/stdc++.h>using namespace std;struct node{ int v,next;} edge[1001];int DFN[1001],LOW[1001];int st[1001],heads...转载 2019-09-28 08:55:46 · 218 阅读 · 2 评论 -
树的重心讲解
https://www.luogu.com.cn/blog/Five-shifts-Forever/shu-di-zhong-xin性质1.树中所有点到某个点的距离和中,到重心的距离和是最小的(边长为1的情况下)。2.将树以某点进行分割后,最大子树包含的节点数为x,以重心进行分割的方案x会最小。......转载 2022-07-07 20:01:49 · 101 阅读 · 0 评论 -
Critical Links UVA - 796 无向图的桥模板
https://www.cnblogs.com/gzh-red/p/11253230.html#_label3_1_2_0原创 2020-04-24 20:13:31 · 109 阅读 · 0 评论 -
Network UVA - 315 无向图的割顶
题目链接:https://vjudge.net/problem/UVA-315#author=0题意:给出一个无向图,求割顶。#include <cstdio>#include <algorithm>#include <queue>#include <vector>#include <cstring>#include <...原创 2020-04-24 16:38:02 · 114 阅读 · 0 评论 -
Board Wrapping UVA - 10652 凸包+向量旋转模板
题目链接:https://vjudge.net/problem/UVA-10652白书P272题意:给多个木板,每块木板用x,y,w,h,j描述。(x,y)为中心点,w,h为宽度和高度。j为顺时针旋转绕中心旋转的角度。用一个面积最小得凸多边形将所有木板包起来,求木板占多边形得面积。思路:先处理木板的顶点,先用角度计算弧度,因为是顺时针需要加负号。向量旋转时因为是绕中心旋转,因此用一个连接木板...原创 2020-04-15 15:04:58 · 113 阅读 · 0 评论 -
线段相交(规范+不规范)
struct point{ double x,y; point(double a=0,double b=0):x(a),y(b) { }};struct line{ point a,b; int id; line() { } line(point c,point d):a(c),b(d) { ...原创 2020-04-14 21:36:39 · 308 阅读 · 0 评论 -
树上差分
转自:https://blog.csdn.net/a_forever_dream/article/details/83505521对点的差分d 是差分数组 a是节点 fa是父节点d[x]+1相当于a[root]~a[x]+1给树上一条链x~y的节点全部+1当 x 是 y 的祖先时d[y]+1,d[fa[x]]-1即可。d[y]+1是给y~root的节点全部+1,d[fa[x]]-1...转载 2020-03-31 10:33:41 · 128 阅读 · 1 评论 -
LCA模板 Nearest Common Ancestors POJ - 1330
转自:https://www.cnblogs.com/morslin/p/11853482.html题目链接:https://vjudge.net/problem/POJ-1330#author=baobaobear#include <iostream>#include <cstdio>#include <cstring>#include <al...转载 2020-03-30 12:27:12 · 93 阅读 · 0 评论 -
Lomsat gelral CodeForces - 600E 树上启发式合并模板 dsu
题目链接:https://vjudge.net/problem/CodeForces-600E转自:https://www.cnblogs.com/zwfymqz/p/9683124.html题意:一棵树,每个节点都有一个颜色,输出出现次数最多的颜色,如果次数相同,就把颜色相加。思路:启发式合并。先通过一次dfs进行树链剖分,把重儿子和轻儿子区分开,然后再进行一次dfs统计答案。统计答案时先...转载 2020-02-14 14:40:34 · 168 阅读 · 0 评论 -
最长公共子序列 Common Subsequence HDU - 1159
题目链接:https://vjudge.net/problem/HDU-1159#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <cmath>#include <vector>#include &...原创 2020-03-08 18:59:31 · 117 阅读 · 0 评论 -
求最长上升子序列长度
转自:https://www.cnblogs.com/xwl3109377858/p/10997588.htmln²写法#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<map>...转载 2020-03-08 18:28:14 · 225 阅读 · 0 评论 -
欧拉phi函数
phi[i]表示小于i且与i互素的数的个数const int maxn=2e6+5;int phi[maxn];void phi_table(){ memset(phi,0,sizeof(phi)); phi[1]=1; for(int i=2; i<=2e6; i++) { if(!phi[i]) { ...原创 2020-02-24 09:02:04 · 363 阅读 · 0 评论 -
中国剩余定理模板 Strange Way to Express Integers POJ - 2891
讲解:https://www.cnblogs.com/zylAK/p/9581919.html取模的数不互素的版本const int maxn=1e5+5;void gcd(long long a,long long b,long long &d,long long &x,long long &y ){ if(!b) { d=a;...原创 2020-02-23 20:42:39 · 109 阅读 · 1 评论 -
无向图的双连通分量 Knights of the Round Table POJ - 2942
点双连通分量即子图中没有割点const int maxn=1e3+5;struct edge{ int u,v;};int pre[maxn],iscut[maxn],bccno[maxn],dfs_clock,bcc_cnt;vector <int> g[maxn],bcc[maxn];//bcc存储每个双连通分量的点stack<edge> s;i...原创 2020-02-21 14:39:15 · 132 阅读 · 0 评论 -
Tarjan模板 Proving Equivalences HDU - 2767缩点法 最少添加多少条边能让图变成强连通图
uvalive数据有问题。题目链接:https://vjudge.net/problem/HDU-2767题意:给一个有向图,问最少添加多少条边能让图变成强连通图。思路:先把图中的强连通分量找出来,把一个强连通分量看成一个点。计算图中入度为0的点的数目a和出度为0的点的数目b,则max(a,b)就是答案。**因为添加上max(a,b)的边后一定可以构成一个环。**特判本身就是强连通图的情况。...原创 2020-02-20 19:57:38 · 155 阅读 · 0 评论 -
差分约束 小K的农场 HYSBZ - 3436
讲解:https://www.cnblogs.com/murmured/p/5004082.htmlhttps://www.cnblogs.com/void/archive/2011/08/26/2153928.html两种不等式第一种: A-B<=val,建一条从B出发到A边权为val的边并跑最短路,求解最大值。第二种:A-B>=val,建一条从B出发到A边权为val的边并跑...原创 2020-02-20 11:09:44 · 182 阅读 · 0 评论 -
最小费用最大流模板 Minimum Cost POJ - 2516
题目链接:https://vjudge.net/problem/POJ-2516题意:输入n,m,k代表商店数、供应商数、商品数。接下来n行表示商店所需的商品情况,m行表示供应商的存货,k个n*m的矩阵代表第i种商品第k个商店从第j个供应商拿去的运输单价,求最小花费。思路:本来想要一个一个的拆点,觉得太麻烦。参考了https://www.cnblogs.com/kangkang-/p/1132.........原创 2020-02-18 20:28:21 · 210 阅读 · 0 评论 -
SPFA模板 Wormholes POJ - 3259
题目链接:https://vjudge.net/problem/POJ-3259题意:给你一个双向图以及走一条路所耗费的时间,有一些单向虫洞,能够把人送到t秒之前,问能否看见之前的自己。思路:判断是否有负圈即可。#include <cstdio>#include <algorithm>#include <queue>#include <vect...原创 2020-02-16 10:53:16 · 88 阅读 · 0 评论 -
Permutation Transformer UVA - 11922 splay分离合并翻转
题目链接:https://vjudge.net/problem/UVA-11922 白书P242#include<cstdio>#include<algorithm>#include<vector>using namespace std;struct Node{ Node *ch[2]; int s; int flip;...原创 2020-02-12 15:40:23 · 140 阅读 · 0 评论 -
Tyvj 1729 文艺平衡树 HYSBZ - 3223 splay翻转区间模板
题目链接:https://vjudge.net/problem/HYSBZ-3223转自:https://www.cnblogs.com/bk-201/p/7390148.html思路:要翻转一个区间[l,r],首先把l-1旋转到树根,然后把r+1旋转到树根的右子节点。因为有一个-inf,所以是l和r+2。#include <bits/stdc++.h>using namesp...原创 2020-02-12 15:02:23 · 86 阅读 · 0 评论 -
Tyvj 1728 普通平衡树 HYSBZ - 3224 Treap树模板
struct Node{ Node *ch[2]; // 左右子树 int r; // 随机优先级 int v; // 值 int s; // 结点总数 Node(int v):v(v) { ch[0] = ch[1] = NULL; r = rand(); s = 1; } bool...原创 2020-02-09 10:16:17 · 120 阅读 · 0 评论 -
莫队模板
转自:https://www.cnblogs.com/WAMonster/p/10118934.html不需要修改值的莫队题目链接:https://vjudge.net/problem/SPOJ-DQUERY#author=0题意:求区间内不同的数的个数把整个区间分块后排序,用双指针移动解决。指针移动优化while(l < ql) now -= !--cnt[aa[l++]];...转载 2020-02-04 16:12:49 · 108 阅读 · 0 评论 -
POJ - 2104 主席树模板
题目链接:https://vjudge.net/problem/POJ-2104转自:https://blog.csdn.net/ModestCoder_/article/details/90107874主席树需要用离散化。a、b数组,一般储存输入数据sz:节点个数rt数组:存储每棵线段树的根节点编号lc、rc数组:记录左儿子、右儿子编号sum数组:记录节点权值 在该节点表示区间内的...转载 2020-02-04 11:24:49 · 76 阅读 · 0 评论 -
UvaLive 4728 求最远点对 旋转卡壳模板
题目链接:https://vjudge.net/problem/UVALive-4728题意:求所有矩形的端点中最大距离。// LA4728/UVa1453 Square// Rujia Liu#include<cstdio>#include<vector>#include<cmath>#include<algorithm>using...原创 2019-10-27 18:39:52 · 115 阅读 · 0 评论 -
容斥原理模板
for(int i=1; i<(1<<N); i++)//代表选取哪些元素 用每一位代表选取与否 { int num=0; for(int j=0; j<N; j++)//挨个判断选择的哪一个元素 { if(i&(1<<...原创 2019-10-18 20:45:35 · 61 阅读 · 0 评论 -
树状数组模板
https://blog.csdn.net/bestsort/article/details/80796531转载 2019-09-30 10:59:33 · 120 阅读 · 0 评论 -
背包问题讲解
https://blog.csdn.net/fguihbfg/article/details/87891379原创 2019-08-26 16:13:22 · 207 阅读 · 0 评论 -
字典树(前缀树)模板
部分摘自:算法竞赛训练指南const int maxnode=1e5+5,sigma_size=26;//总结点数 每个节点的分支数struct Trie{ int ch[maxnode][sigma_size];//保存节点为i的编号为j的节点 int val[maxnode];//记录此节点是否是一个串的结尾 int sz;//节点总数 Trie() .........原创 2019-08-18 09:59:08 · 121 阅读 · 0 评论 -
Manacher‘s Algorithm 求最长回文子串
https://blog.csdn.net/MallowFlower/article/details/87701363原创 2019-08-17 20:12:16 · 98 阅读 · 0 评论 -
AC自动机模板
const int maxn = 2*1e6+9;int trie[maxn][26]; //字典树int cntword[maxn]; //记录该单词出现次数int fail[maxn]; //失败时的回溯指针int cnt = 0;void insertWords(string s){ int root = 0; for(int i=0;i<s....原创 2019-08-17 18:28:12 · 84 阅读 · 0 评论 -
KMP模板
next数组作用:http://www.sohu.com/a/334290971_701814原创 2019-08-17 17:11:39 · 102 阅读 · 0 评论 -
卢卡斯定理模板
long long qsm(long long a,long long b,long long m){ long long res=1; while(b) { if(b&1) { res=res*a%m; } a=a*a%m; b>>=1; ...原创 2019-08-14 11:36:43 · 149 阅读 · 0 评论 -
KM模板
const int maxn=2e3+7;int love[maxn][maxn];int ex_girl[maxn],ex_boy[maxn];bool vis_girl[maxn],vis_boy[maxn];int match[maxn];int slack[maxn];int nx,ny;vector<pair<int,int> >vec;bool ...原创 2019-08-14 11:38:10 · 178 阅读 · 0 评论 -
矩阵快速幂求斐波那契模板
https://blog.csdn.net/NYIST_TC_LYQ/article/details/52981353注意原文章是求了n次幂,所以第一项为第n+1位的斐波那契,第二项才是第n位。原创 2019-08-14 11:58:36 · 80 阅读 · 0 评论 -
博弈论讲解
https://blog.csdn.net/pengwill97/article/details/76796070#commentBox原创 2019-10-04 22:47:08 · 229 阅读 · 0 评论 -
字符串hash讲解
https://www.cnblogs.com/–ZHIYUAN/p/7445842.html#3956691转载 2019-08-22 11:22:49 · 77 阅读 · 0 评论 -
拓扑排序模板
hdu 1285题意:给你n个数,m行输入,每行输入的两个数a,b代表a<b,输出大小关系,要求字典序最小。注意题目中已经说一定有答案,即没有自环。坑点:拓扑排序并且字典序最小,紫书上的模板不能输出字典序最小但可以判断自环。#include <bits/stdc++.h>using namespace std;const int maxn=505;int g[max...原创 2019-08-20 15:55:24 · 206 阅读 · 0 评论 -
线段树模板
线段树:https://blog.csdn.net/huangzihaoal/article/details/81813454原创 2019-09-08 16:34:18 · 80 阅读 · 0 评论 -
回文树模板 hdu3948
题目链接:https://vjudge.net/problem/HDU-3948题意:输出每个串有多少个子串是回文串转自:http://www.pianshen.com/article/86272661/因为一开始就有了两个节点,所以输出是应该-2.#include <bits/stdc++.h>using namespace std;const int MAXN = 10...原创 2019-09-11 16:21:14 · 144 阅读 · 0 评论