
模板
吴俊达9812
这个作者很懒,什么都没留下…
展开
-
L - Limited Permutation
递归爆栈,改成非递归的模板题 #include <bits/stdc++.h> using namespace std; typedef int lint; typedef long long LL; typedef pair<lint,lint> pii; const lint maxn = 1000005; ...原创 2019-07-13 21:55:10 · 263 阅读 · 0 评论 -
图论知识点
边覆盖:最小的边集使得每个点都与至少一个点相连点覆盖:最小的点集使得每个点都与至少一条边相连匹配数 定义为 边独立数对于任意图: 边覆盖数 = 点独立数 边覆盖数 + 点覆盖数 = 节点数 所以 点覆盖数 + 点独立数 = 节点数对于二分图:点独立数 + 最...原创 2019-08-01 19:08:42 · 724 阅读 · 0 评论 -
匈牙利算法
#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;const lint maxn = 5000 + 100;const lint maxm = 50000000 + 100;lint lowbit( lint x ){ return x & -...原创 2019-08-02 14:13:11 · 128 阅读 · 0 评论 -
蔡勒公式
公式1: 1582年10月4日之后:w=y1+(y1/4)+(c/4)-2*c+(26*(m+1)/10)+d-1; 1582年10月4日以及之前:w=y1+y/4+c/4-2*c+13*(m+1)/5+d+2; 输出:(w%7+7)%7 (为了确保结果为正数)说明: w为星期, 0-星期日,1-星期一,..........6-星期六...转载 2019-08-07 10:35:27 · 221 阅读 · 0 评论 -
P3804 【模板】后缀自动机
思路:right 集合出现的次数的求法是将所有节点的按照len进行排序,并且将所有包含前缀的节点的 sz 置为1.最后按照len从大到小的顺序 执行 sz[ fa[x] ] += sz[x] 的操作。#include <bits/stdc++.h>using namespace std;const int maxn = 1000005;const int maxm = 2...原创 2019-08-07 11:28:49 · 140 阅读 · 0 评论 -
哈密顿图
转载 2019-08-23 21:23:25 · 285 阅读 · 0 评论 -
luogu P4323 [JSOI2016]独特的树叶
hash 的方式,我觉得这个是找了这么久最好写的hash了,貌似也不容易被卡。Hash=(Hash[son1]+p)⨁(Hash[son2]+p)⨁……+size∗q+1#include <bits/stdc++.h>using namespace std;typedef unsigned long long ull;typedef long long LL;con...原创 2019-08-22 22:32:05 · 112 阅读 · 0 评论 -
bzoj 1010: [HNOI2008]玩具装箱toy
斜率优化还是用浮点数的写法好写啊,以后就这么写了,还不会错(因为斜率相等的情况对于斜率优化是无所谓的,所以说浮点数误差不会导致错误)#include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxn = 50005;int C[maxn],q[maxn];LL sum[maxn]...原创 2019-08-26 21:30:54 · 136 阅读 · 0 评论 -
poj 3691 DNA repair
记忆化搜索+AC自动机我这题犯的最大的错误就是 写记忆化搜索的时候,进去之后就将dp值赋为0,这样如果后面没有可行方案的话dp值还是0。多组测试样例的模板#include <map>#include <queue>#include <cstring>#include <cstdio>using namespace std;co...原创 2019-08-28 22:39:04 · 156 阅读 · 0 评论 -
2019 ccpc 网络赛 K-th occurrence(排名lcp模板)
题意:查询子串在原串中第k次出现的位置思路: ST表 + 主席树 + 后缀数组#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;const lint maxn = 100000 + 10;const lint log_maxn = 20;typedef...原创 2019-08-23 18:32:15 · 357 阅读 · 0 评论 -
牛客多校2Eddy Walker 2
线性递推的下界 BM算法复杂度 k^2 * logn正常矩阵快速幂 k^3 * logn( k 表示每一项由前k项递推得到 ,n代表要得到的项)看到咖啡鸡的代码 把前2*k+1项扔进去就可以了。#include<bits/stdc++.h>#define MAXN 100005#define INF 1000000000#define MOD 100000000...原创 2019-08-29 13:37:31 · 210 阅读 · 0 评论 -
费用流模板
题意:在一个篮球联赛里,有n支球队,球队的支出是和他们的胜负场次有关系的,具体来说,第i支球队的赛季总支出是Ci*x^2+Di*y^2,Di<=Ci。(赢得多,给球员的奖金就多嘛)其中x,y分别表示这只球队本赛季的胜负场次。现在赛季进行到了一半,每只球队分别取得了a[i]场胜利和b[i]场失利。而接下来还有m场比赛要进行。问联盟球队的最小总支出是多少。亲测起点和终点的距离较短时d...原创 2019-09-17 21:31:45 · 106 阅读 · 0 评论 -
codeforces 1101D 点分治模板(注释掉的地方是需要自己填充的)
题意:一颗树,每个点有权值,问最长路径使得路径上的点的gcd > 1点分治写法的注意事项:一条分治完全处理完之后才可以更新,不能出栈的时候更新。技巧:使用mark数组#include <cstdio>#include<vector>#include<cstring>#include<algorithm>#include&...原创 2019-09-18 15:24:50 · 181 阅读 · 0 评论 -
质因数分解模板
vector<int> ve[maxn]; for( int i = 1;i <= 200000;i++ ){ int c = i; for( int j = 2;j*j<= c;j++ ){ if( c % j == 0 ){ ve[i].push_back( j ); ...原创 2019-09-18 15:27:09 · 179 阅读 · 0 评论 -
ISAP 模板
#include<bits/stdc++.h>using namespace std;typedef long long lint;typedef long long LL;const lint maxn = 10010;const lint maxm = 10010;const LL INF = 0x3f3f3f3f3f3f3f3f;lint tot,ver[maxm...原创 2019-09-18 16:41:47 · 212 阅读 · 0 评论 -
组合数模板
对于 n,m <= 1e8直接递推求 1 ~ 1e8的阶乘 frac[ i ]求出对应的逆元 carf[ i ]C( n,m ) = frac[ n ] * carf[ n-m ]*carf[ m ]typedef unsigned long long ll;#define maxn 1002000const ll oo=1000003;ll frac[maxn]...原创 2019-06-22 19:41:10 · 119 阅读 · 0 评论 -
焦作网络赛 E.Jiu Yuan Wants to Eat
更新了板子,原来的常数太大了这里取反运算是对 64 位全部取反,相当于 *(-1) + 2e64-1 = *( 2e64-1 )+2e64-1还有一个问题就是先乘后加可以拆分成 乘 和 加,这样可以降低代码长度坑点:unsigned long long 读入和输出都是是%llu#include <bits/stdc++.h>#define lc l,mid,x...原创 2019-06-25 20:15:08 · 208 阅读 · 0 评论 -
dijstra 模板
priority_queue< pair<LL,int>,vector< pair<LL,int> >,greater< pair<LL,int> > > que;int vis[maxn];LL dist[maxn];void dijkstra( int s,int n ){ while( que.size(...原创 2019-04-23 19:58:04 · 206 阅读 · 0 评论 -
RMQ模板
void init( LL s,LL t ){ LL dt = t-s; log[1] = 0; for( LL i = 2;i <= dt;i++ ) log[i] = i&(i-1) ? log[i-1] : log[i-1] + 1;}void build1( LL s,LL t,LL rmq[][20] ){ LL dt = t-s; ...原创 2019-04-23 20:01:06 · 137 阅读 · 0 评论 -
dinic
typedef long long LL;typedef LL lint;const lint inf = 0x3f3f3f3f3f3f;const int maxn = 200;const int maxm = 200;struct dinic{ static const int N = 1000005; static const int M = 20000005;...原创 2019-04-23 20:20:13 · 486 阅读 · 0 评论 -
bzoj 1565植物大战僵尸
题意:很麻烦,就不说了思路:有向闭合图:闭合图中任意点的后继还在闭合图中。 物理意义:一个事件发生,他所有的前提都需要发生 在任意有向带权图中,只要有依赖关系需要解决,最大权闭合子图都普遍成立。 拓扑排序中没有遍历到的点就是不可达点,不可达点不能在网络流中出现。为啥呢,我试了一下,把这些点放入网络流中 ...原创 2019-05-16 22:22:47 · 146 阅读 · 0 评论 -
洛谷 P3796 AC自动机模板
题意:统计出现次数最多的字符串,按照输入顺序输出这些字符串#include <bits/stdc++.h>using namespace std;typedef int LL;const LL maxn = 500000 + 100;LL re = -1,ma[maxn],ccnt[maxn];void init(){ memset( ccnt,0,sizeof...原创 2019-05-22 21:16:14 · 132 阅读 · 0 评论 -
【BZOJ 1251】序列终结者 splay模板
模板:区间反转,区间加某一个值,区间求最大值坑点:首尾各加上两个节点后,注意第一个新加点的初值。这个东西应该叫名次树吧,写完这个东西最大的体会就是,树上每个节点的标号其实就是人们思维上那个点应该出现的value的索引值,怎么标并不重要。#include<bits/stdc++.h>typedef long long LL;typedef int lint;using...原创 2019-05-27 22:40:58 · 165 阅读 · 0 评论 -
lca模板
// 节点编号从1开始const lint maxn = 200000 + 10;const lint maxm = 500000;lint ver[maxm],ne[maxm],he[maxn],tot;vector<lint> vex,vey;void init(){ memset( he,0,sizeof( he ) ); tot = 1;}voi...原创 2019-05-28 10:59:28 · 135 阅读 · 0 评论 -
spoj 1825
这题貌似用启发式合并的话复杂度为nlogn,然而我不会,于是用 树状数组写的,复杂度 n(logn)2,跑了900多ms。 用树状数组有一个坑,就是树状数组的下表从1 开始,但是可能存在路径上关键节点为0的情况,那么我们给每条路径关键节点个数加一,就避免了这种情况。还有一个问题是如果根节点本身是关键节点的话,需要把两条路径的个数的和减1.还有就是树状数组清空如果memset会超时,于是我记录了...原创 2019-06-13 17:00:21 · 174 阅读 · 0 评论 -
URAL 1297 最长回文子串(LCP模板)
//最长回文子串 , lcp 模板#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;const lint maxn = 2000 + 10;typedef int lint;struct suffix{ lint c[maxn],sa[maxn],...原创 2019-06-08 12:04:09 · 198 阅读 · 0 评论 -
distinct substrings
//本质不同的子串个数#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;const lint maxn = 1000 + 10;typedef int lint;struct suffix{ lint c[maxn],sa[...原创 2019-06-07 13:06:40 · 204 阅读 · 0 评论 -
poj 3261
//最少重叠k次的最长子串#include <vector>#include<cstdio>#include<algorithm>#include<iostream>#include<cstring>using namespace std;typedef long long LL;typedef int...原创 2019-06-07 12:18:37 · 155 阅读 · 0 评论 -
poj 1743
男人8题,又改了一次板子//最长不重叠重复子串#include <cstdio>#include<cstring>#include<iostream>using namespace std;typedef long long LL;typedef int lint;const lint maxn = 20000 + 10;const ...原创 2019-06-06 23:43:49 · 143 阅读 · 0 评论 -
POJ 2774( 后缀数组模板 )
注意 :swap( x[N],y[N] ) 复杂度为O(N),不要直接swap//最长公共子串#include <cstdio>#include<cstring>#include<iostream>using namespace std;typedef long long LL;typedef int lint;c...原创 2019-06-05 21:46:28 · 207 阅读 · 0 评论 -
质数筛模板
struct Primes{ static const int N = ; int v[N],prime[N],m; void primes( int n ){ memset( v,0,sizeof( v ) ); m = 0; for( int i = 2;i <= n;i++ ){ if( ...原创 2019-06-09 23:59:42 · 693 阅读 · 0 评论 -
树链剖分模板(点)
#include <bits/stdc++.h>#define lc l,mid,x<<1#define rc mid+1,r,x<<1|1#define ls x<<1#define rs x<<1|1using namespace std;typedef unsigned long long LL;const int ...原创 2019-09-18 19:58:22 · 75 阅读 · 0 评论