![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
————模板————
Michael_GLF
AFOing
展开
-
每日模板一练——树链剖分换根操作
传送门【题目分析】qwq数据结构调起来真是有毒。换根后只会对子树的查询和修改造成影响,很明显,如果修改位置x与root的lca非x,那么不会有影响,如果是x,那么分根是x和不是x两种情况,第一种输出tr[1].sum即可,第二种直接全体操作然后对x到rt第一个点子树进行操作即可。【代码~】#include<bits/stdc++.h>using namespac...原创 2019-01-21 12:10:45 · 343 阅读 · 0 评论 -
最小费用流模板
思路:每次先以价值为边权走一遍SPFA,沿最短路增广。#include<bits/stdc++.h>using namespace std;typedef long long LL;const LL MAXN=501;const LL MAXM=3e4+10;const LL INF=0x3f3f3f3f;LL n,m,s,t,cnt;LL head[MAXN],...原创 2018-09-28 21:57:19 · 413 阅读 · 0 评论 -
每日模板一练(KMP)
大意:给出两个字符串s1,s2,求s1中包含多少不重叠的子串=s2样例:aaaaaa aaabcde a2输出:30 #include<bits/stdc++.h>using namespace std;const int MAXN=1001;int nxt[MAXN];string s1,s2;void make_next(string ...原创 2018-10-08 20:08:10 · 107 阅读 · 0 评论 -
每日模板一练(Dijkstra堆优化)
大意:给一个图,N个点M条边,求s到t最短路径#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<queue>using namespace std;int Rea...原创 2018-10-09 18:38:54 · 157 阅读 · 4 评论 -
每日模板一练——树状数组求逆序对
大意:给你N个数,求逆序对个数(树状数组)代码:#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define LL long longusing namespace std;LL n,x,tree[100010];void add...原创 2018-10-10 18:46:31 · 92 阅读 · 0 评论 -
每日模板一练——树链剖分求LCA(好吧是真的写错了)
大意给一个N个节点的树和M个询问,对于每次询问输出两点的距离。样例:61 21 32 42 53 622 65 6输出:34【代码~】#include<bits/stdc++.h>using namespace std;const int MAXN=1e5+10;const int MAXM=3e5+10;int n,m,cn...原创 2018-10-11 19:10:54 · 101 阅读 · 0 评论 -
每日模板一练——矩阵快速幂
打个模板防止手生了吧。。。大意:求Febnaci第n项(n<=1e9)#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const int MOD=1e...原创 2018-10-11 21:49:45 · 101 阅读 · 0 评论 -
每日模板一练——快速幂和快速乘的结合
在这个快速幂已经铺大街的时候,总有睿(毒)智(瘤)的出题人会卡卡你的精度,比如1e9的1e9次方什么的,这时候就是快速幂与快速乘的结合啦!快速乘的写法跟快速幂的写法一毛一样嘛!代码~#include<bits/stdc++.h>using namespace std;typedef long long LL;LL a,b,c;LL ksc(LL a1,LL b1,L...原创 2018-10-15 21:13:47 · 131 阅读 · 0 评论 -
每日模板一练——Trie树
POJ3630又是YES和NO,判反了判反了。。。。。再这样我就女装了!#include<bits/stdc++.h>using namespace std;const int N=5e5+10;struct T{ int son[10]; int num;}trie[N];int tot;char str[100];int flag=0;void i...原创 2018-10-16 19:05:40 · 87 阅读 · 0 评论 -
每日模板一练——Tarjan缩点
BZOJ1718重边的存在让我很难受啊。。。。无向图的缩点,记录入度,如果为1就ans++(代码因为统计了两次所以为2就++)#include<cstdio>#include<algorithm>using namespace std;int head[5005],nxt[20005],to[20005],tot,_tot,num[20005],fa[20...原创 2018-10-17 19:52:25 · 106 阅读 · 0 评论 -
每日模板一练——扩展欧几里得
JZOJ5855有毒吧,这都卡long long(毒瘤改数据),必须用龟速乘才能过最后一个点。题目就是让求ax+by=c的非负整数解的组数,扩欧就行了【代码~】#include<bits/stdc++.h>using namespace std;typedef long long LL;LL T,ansx,ansy;LL ksc(LL a,LL b,LL ...原创 2018-10-18 20:07:34 · 173 阅读 · 0 评论 -
每日模板一练——并查集
洛谷2814极度细(毒)节(瘤)的字符串处理,以及最后一步弄错。。。。。(水了70分?)【代码~】 #include<bits/stdc++.h>using namespace std;const int MAXN=5e4+10;map<string,int> name;map<int,string> id;map<string...原创 2018-10-19 19:01:49 · 138 阅读 · 0 评论 -
每日模板一练——最小生成树
洛谷1550构图很巧妙,建立一个超级源点,所有连向自己的边(即打井)改为连向这个超级源点,最后跑一个最小生成树即可。#include<bits/stdc++.h>using namespace std;const int MAXN=1e5+10;struct node{ int from,to,w; friend inline bool operato...原创 2018-10-22 20:54:00 · 184 阅读 · 0 评论 -
每日模板一练——高精度加减法
什么毒瘤!!!!当场去世!!!!#include<bits/stdc++.h>using namespace std;const int MAXN=1e7+10;struct hugeint{ int len,a[MAXN]; hugeint(){ memset(a,0,sizeof(a));len=1; } bool op...原创 2018-10-24 19:30:11 · 132 阅读 · 0 评论 -
洛谷3384 树链剖分(模板)
我 服 我 自 己【题目分析】板子题调一天系列。。。。qwq已经被蠢死。路径操作直接上树链剖分,子树操作直接在线段树上区间修改询问(因为x及其子树的dfs序为dfn[x]~dfn[x]+siz[x]-1)然后就是一群人对着这份代码看了半天没挑出错来。。。。【代码~】#include<bits/stdc++.h>using namespace std;con...原创 2018-10-29 15:03:08 · 163 阅读 · 0 评论 -
每日模板一练——进制转换
输入两个整数n,k,第一个为十进制下的数,将n转化为k进制。#include<bits/stdc++.h>using namespace std;const int MAXN=51;int n,k;int cnt;char num[MAXN];int Read(){ int i=0,f=1; char c; for(c=getchar();(c>'9'|...原创 2018-10-30 18:46:00 · 176 阅读 · 0 评论 -
每日模板一练——高斯消元
RT#include<bits/stdc++.h>using namespace std;const int MAXN=105;const double eps=1e-3;int n;double a[MAXN][MAXN];double ans[MAXN];void gauss(){ int i,j,k; for(i=1;i<=n;++i){ f...原创 2018-10-31 18:47:13 · 95 阅读 · 0 评论 -
每日模板一练——拓扑排序
士兵站队问题#include<bits/stdc++.h>using namespace std;int n,x,y,cnt;int du[1005],Head[1005],nxt[2010],to[2010];int vis[1005],use[1005];queue<int> q,Q;void add(int u,int v){ ++cnt; ...原创 2018-11-02 19:09:00 · 93 阅读 · 0 评论 -
【模板】维护序列2(线段树)
内网传送门【题目分析】取模取挂可真是令人质壁分离。。。。两两乘积和可以直接用两个区间的区间和相乘再加上两个区间各自的乘积和得到,而相邻乘积和直接两段相加再加上左区间右端点与右区间左端点乘积就好了。注意+MOD%MOD【代码~】#include<bits/stdc++.h>using namespace std;typedef long long LL;c...原创 2019-09-20 18:58:32 · 181 阅读 · 0 评论