![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
比赛用模板
tomjobs
别慌,慌也没用
展开
-
P3386 【模板】二分图最大匹配(匈牙利算法,网络流)
匈牙利#include <cstring>#include <cstdio>#include <algorithm>#include <vector>using namespace std;const int maxn = 1e3 + 7;vector<int>G[maxn];int match[maxn],vis[maxn];int n,m,e;void add(int x,int y) { G[x].push_b.原创 2021-03-09 20:18:52 · 227 阅读 · 0 评论 -
P5357 【模板】AC自动机(二次加强版)(AC自动机拓扑排序优化)
思路:最坏情况下FailFailFail树上每跳一次深度减1,那么queryqueryquery操作的最坏复杂度为O(∣∑T∣∗∣S∣)O(|∑T|*|S|)O(∣∑T∣∗∣S∣),本题中的话就是2e5∗2e62e5*2e62e5∗2e6,这是不可接受的。不过因为很明显仅考虑failfailfail指针的话,每个节点只会指向深度更小的节点,所以不会成环,就构成了一个DAG图。每个节点的答案由为自己的节点的答案的和。因此,queryqueryquery的过程我们不暴力跳failfailfail指针,只.原创 2021-02-04 11:30:06 · 410 阅读 · 0 评论 -
yin间加速卡常大法
不知道来源是哪,侵删#pragma comment(linker, "/stack:200000000")#pragma GCC optimize("Ofast,no-stack-protector")#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")#pragma GCC optimize("unroll-loops")原创 2020-10-03 19:52:23 · 194 阅读 · 0 评论 -
双向链表(指针写法,数组写法)
改了个链表需求。。。所以就贴上来了#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <vector>#include <map>using namespace std;const int INF = 0x3f3f3f3f;map<int,int>mp;struct Node { int原创 2020-10-02 23:56:46 · 305 阅读 · 0 评论 -
P3806 【模板】点分治1
题目描述给定一棵有 nn 个点的树,询问树上距离为 kk 的点对是否存在。思路:直接在点分治模板的双指针上加上了100次询问(竟然没有T)#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <vector>#include <queue>#include <iostream>#include &l原创 2020-09-28 10:00:33 · 191 阅读 · 0 评论 -
双连通分量(边、点)模板
点双连通分量const int SIZE = 2e5 + 7;int head[SIZE], ver[SIZE * 2], Next[SIZE * 2];int dfn[SIZE], low[SIZE], stack[SIZE];int cut[SIZE], color[SIZE], vis[SIZE], CNT[SIZE];void tarjan(int x) { dfn[x] = low[x] = ++num; stack[++top] = x; int flag =原创 2020-09-08 13:36:20 · 266 阅读 · 0 评论 -
SP104 HIGH - Highways(基尔霍夫矩阵,生成树个数,求矩阵行列式值)
题目描述In some countries building highways takes a lot of time… Maybe that’s because there are many possiblities to construct a network of highways and engineers can’t make up their minds which one to choose. Suppose we have a list of cities that can be conn原创 2020-08-07 13:32:40 · 271 阅读 · 0 评论 -
unordered_map使用pair
转自知乎。加上pair的哈希函数就好了。struct pairhash {public: template <typename T, typename U> std::size_t operator()(const std::pair<T, U> &x) const { return std::hash<T>()(x.first) ^ std::hash<U>()(x.second); }};原创 2020-08-03 10:16:13 · 1908 阅读 · 2 评论 -
AcWing 382. K取方格数(费用流)
在一个N*N的矩形网格中,每个格子里都写着一个非负整数。可以从左上角到右下角安排K条路线,每一步只能往下或往右,沿途经过的格子中的整数会被取走。若多条路线重复经过一个格子,只取一次。求能取得的整数的和最大是多少。输入格式第一行包含两个整数N和K。接下来N行,每行包含N个不超过1000的整数,用来描述整个矩形网格。输出格式输出一个整数,表示能取得的最大和。数据范围1≤N≤50,0≤K≤10输入样例:3 21 2 30 2 11 4 2输出样例:15思路:费用流就是,每个原创 2020-07-24 18:11:12 · 378 阅读 · 0 评论 -
Paint Color Aizu - 0531(坐标离散化)
题意:W*H的白色平面,已有给出n个黑色矩形,求多少个白色连通块思路:白书原题就是把每个直线上、直线上、直线下的用作计算,忽略其他点达到离散化的目的。最后W,H的规模都不会很大,所以直接跑bfs或者dfs记录连通块即可#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <queue>using namespace s原创 2020-07-23 21:28:36 · 231 阅读 · 0 评论 -
杭电多校第一场 Fibonacci Sum HDU - 6755 Power of Fibonacci ZOJ - 3774(斐波那契数列幂次和)
In mathematics, Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers of the following integer sequence:1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, …By definition, the first two numbers in the Fibonacci sequence are 1 and 1原创 2020-07-22 12:40:49 · 270 阅读 · 0 评论 -
P3376 【模板】网络最大流(dinic模板)
因为牛客第一场,被迫学习网络流。#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<queue>using namespace std;typedef long long ll;const int inf = 1 << 29, N = 50010, M = 300010;原创 2020-07-13 16:38:34 · 271 阅读 · 1 评论 -
Cornfields POJ - 2019(二维rmq)
FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he’s looking to build the cornfield on the flattest piece of land he can find.FJ has, at great expense, surveyed his square farm of N x N hectar原创 2020-06-27 14:27:51 · 297 阅读 · 0 评论 -
HDU2222 Keywords Search(AC自动机模板题)
Problem DescriptionIn the modern time, Search engine came into the life of everybody like Google, Baidu, etc.Wiskey also wants to bring this feature to his image retrieval system.Every image have a long description, when users type some keywords to find原创 2020-06-21 14:52:10 · 244 阅读 · 0 评论 -
A hole to catch a man UVA - 10060(求凸包/多边形面积)
How can a manhole be a hole if it is covered? Perhaps, to prove a manhole a hole, most of the manholesof Dhaka are uncovered. So now manhole means a hole to catch a man. Anyway, the new Mayor ofDhak...原创 2019-12-13 14:16:14 · 235 阅读 · 0 评论 -
随机数生成器
转自学长,侵删(捂脸#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <string>#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#de...原创 2020-04-22 09:11:05 · 334 阅读 · 0 评论 -
Nephren Runs a Cinema CodeForces - 896D(卡特兰数,模数非质数求组合数)
Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema.However, one day, the No. 68 Cinema runs out of changes (they don’t have 50-yuan notes currently), but Ne...原创 2020-04-08 23:40:31 · 519 阅读 · 0 评论 -
洛谷P2485 [SDOI2011]计算器(BGSG算法)
题意:给定 y,z,p,计算 yz mod py^z \bmod pyzmodp给定 y,z,p,计算满足 xy≡z(modp)xy \equiv z \pmod pxy≡z(modp)给定 y,z,p,计算满足 yx≡z(modp)y^x \equiv z \pmod pyx≡z(modp)思路:对于ax+by=cax+by=cax+by=c线性同余方程求解时的通解x=x0∗c/d+k...原创 2020-03-23 18:23:27 · 663 阅读 · 0 评论 -
洛谷P3389 【模板】高斯消元法
https://www.luogu.com.cn/problem/P3389试验模板#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n;double a[1005][1005];void init(){ scanf("%d...原创 2020-02-12 16:45:50 · 140 阅读 · 2 评论 -
ACWING140. 后缀数组
后缀数组 (SA) 是一种重要的数据结构,通常使用倍增或者DC3算法实现,这超出了我们的讨论范围。在本题中,我们希望使用快排、Hash与二分实现一个简单的O(nlog2n)的后缀数组求法。详细地说,给定一个长度为 n 的字符串S(下标 0~n-1),我们可以用整数 k(0≤k<n) 表示字符串S的后缀 S(k~n-1)。把字符串S的所有后缀按照字典序排列,排名为 i 的后缀记为 SA[...原创 2019-10-27 20:45:55 · 274 阅读 · 0 评论 -
Cycle HDU - 5215(判断奇数环和偶数环,边双连通分量)
Ery is interested in graph theory, today he ask BrotherK a problem about it: Given you a undirected graph with N vertexes and M edges, you can select a vertex as your starting point, then you need to ...原创 2019-09-06 11:19:51 · 1071 阅读 · 0 评论 -
逃生 HDU - 4857(拓扑排序模板题)
糟糕的事情发生啦,现在大家都忙着逃命。但是逃命的通道很窄,大家只能排成一行。现在有n个人,从1标号到n。同时有一些奇怪的约束条件,每个都形如:a必须在b之前。同时,社会是不平等的,这些人有的穷有的富。1号最富,2号第二富,以此类推。有钱人就贿赂负责人,所以他们有一些好处。负责人现在可以安排大家排队的顺序,由于收了好处,所以他要让1号尽量靠前,如果此时还有多种情况,就再让2号尽量靠前,如果还有...原创 2019-08-20 00:34:11 · 179 阅读 · 0 评论 -
BZOJ1191. [HNOI2006]超级英雄Hero(二分图匹配)
Description现在电视台有一种节目叫做超级英雄,大概的流程就是每位选手到台上回答主持人的几个问题,然后根据回答问题的多少获得不同数目的奖品或奖金。主持人问题准备了若干道题目,只有当选手正确回答一道题后,才能进入下一题,否则就被淘汰。为了增加节目的趣味性并适当降低难度,主持人总提供给选手几个“锦囊妙计”,比如求助现场观众,或者去掉若干个错误答案(选择题)等等。这里,我们把规则稍微改变...原创 2019-10-05 19:28:27 · 210 阅读 · 0 评论 -
H - Rock Paper Scissors Gym - 101667H(FFT)
There is a Rock Paper Scissors (RPS) machine which generates Rock, Paper, or Scissors randomly. You also have a similar small Rock Paper Scissors machine. Before the game, the RPS machine will generat...原创 2019-10-05 17:26:50 · 508 阅读 · 0 评论 -
1798: [Ahoi2009]Seq 维护序列seq(线段树乘法加法)
Description老师交给小可可一个维护数列的任务,现在小可可希望你来帮他完成。 有长为N的数列,不妨设为a1,a2,…,aN 。有如下三种操作形式: (1)把数列中的一段数全部乘一个值; (2)把数列中的一段数全部加一个值; (3)询问数列中的一段数的和,由于答案可能很大,你只需输出这个数模P的值。Input第一行两个整数N和P(1≤P≤1000000000)。第二行含有N个非负整数,...原创 2019-08-25 20:51:58 · 185 阅读 · 0 评论 -
BZOJ1856: [Scoi2010]字符串(卡特兰数,组合数,欧几里得求逆元)
Descriptionlxhgww最近接到了一个生成字符串的任务,任务需要他把n个1和m个0组成字符串,但是任务还要求在组成的字符串中,在任意的前k个字符中,1的个数不能少于0的个数。现在lxhgww想要知道满足要求的字符串共有多少个,聪明的程序员们,你们能帮助他吗?Input输入数据是一行,包括2个数字n和mOutput输出数据是一行,包括1个数字,表示满足要求的字符串数目,这个数可能...原创 2019-08-25 17:34:31 · 223 阅读 · 0 评论 -
Oulipo POJ - 3461(KMP模板题)
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter ‘e’. He was a member of the Oulipo group. A quote from the book:Tout avait Pair normal, mais tout s’a...原创 2019-08-15 19:27:32 · 176 阅读 · 0 评论 -
最短路模板
#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace std;#define INF 0x3f3f3f3fconst int maxn = 2e5 + 7;int n,m,tot;int dis[maxn],vis...原创 2019-08-14 23:49:31 · 166 阅读 · 0 评论 -
142. 前缀统计 ACwing(字典树模板题)
给定N个字符串S1,S2…SN,接下来进行M次询问,每次询问给定一个字符串T,求S1~SN中有多少个字符串是T的前缀。输入字符串的总长度不超过106,仅包含小写字母。输入格式第一行输入两个整数N,M。接下来N行每行输入一个字符串Si。接下来M行每行一个字符串T用以询问。输出格式对于每个询问,输出一个整数表示答案。每个答案占一行。输入样例:3 2abbcabcabcef...原创 2019-08-19 22:55:14 · 173 阅读 · 0 评论 -
素数筛,组合数模板
埃式筛void getprime(){ vis[2] = 0; for(int i = 2;i <= maxn;i++) { if(vis[i] == 1) continue; prime[++prime[0]] = i; for(int j = i * i;j <= maxn;j +=...原创 2019-08-14 16:25:26 · 193 阅读 · 0 评论 -
hdu3555 bomb(数位dp模板题)
BombTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 27885 Accepted Submission(s): 10606Problem DescriptionThe counter-terrorists found a...原创 2019-08-19 16:46:46 · 162 阅读 · 0 评论 -
快速乘模板 / 三种方法 ACWING90. 64位整数乘法
求 a 乘 b 对 p 取模的值。输入格式第一行输入整数a,第二行输入整数b,第三行输入整数p。输出格式输出一个整数,表示a*b mod p的值。数据范围1≤a,b,p≤1018输入样例:345输出样例:2快速乘模板#include <cstdio>#include <cmath>#include <algorithm>#inc...原创 2019-08-13 23:50:02 · 259 阅读 · 0 评论 -
焦作区域赛E - Resistors in Parallel Gym - 102028E(高精度)
In this physics problem, what we are concerned about are only resistors. If you are poor at physics, do not worry, since solving this problem does not require you to have advanced abilities in physics...原创 2019-08-21 19:37:12 · 326 阅读 · 0 评论 -
acm快读模板
orz qscqeszeinline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}...原创 2019-08-21 20:52:16 · 848 阅读 · 0 评论 -
组合数逆元模板(3种方法)
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int mod = 1e9 + 7;const int maxn = 2e5 + 7;typedef long long ll;st...原创 2019-08-21 22:31:32 · 462 阅读 · 0 评论 -
AcWing 307. 连通图 poj1737(计数类dp,高精度)
求 N 个节点的无向连通图有多少个,节点有标号,编号为1~N。例如下列图示,三个节点的无向连通图共4个。1737_1.jpg输入格式输入包含多组测试数据。每组数据包含一个整数N。当输入为0时,表示输入终止。输出格式每组测试数据输出一个结果,每个结果占一行。数据范围1≤N≤50输入样例:12340输出样例:11438思路:f[i] = 2i*(i-1)/...原创 2019-10-01 18:42:36 · 249 阅读 · 0 评论 -
lca倍增和离线tarjan模板
https://www.luogu.org/problem/P3379#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1e6 + 7;int head[maxn],to[maxn],nex[maxn],d[max...原创 2019-09-14 11:55:38 · 203 阅读 · 0 评论 -
树状数组区间更新区间查询模板
现在还没看懂,先记录下来#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int SIZE=100010;int a[SIZE],n,m;long long c[2][SIZE],sum[SI...原创 2019-09-11 10:32:57 · 153 阅读 · 0 评论 -
洛谷P1816 忠诚(倍增dp,rmq)
题目描述老管家是一个聪明能干的人。他为财主工作了整整10年,财主为了让自已账目更加清楚。要求管家每天记k次账,由于管家聪明能干,因而管家总是让财主十分满意。但是由于一些人的挑拨,财主还是对管家产生了怀疑。于是他决定用一种特别的方法来判断管家的忠诚,他把每次的账目按1,2,3…编号,然后不定时的问管家问题,问题是这样的:在a到b号账中最少的一笔是多少?为了让管家没时间作假他总是一次问多个问题。输...原创 2019-09-07 11:42:00 · 223 阅读 · 0 评论 -
Popular Cows POJ - 2186(tarjan缩点,模板)
Every cow’s dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M <= 50,000) ordered pairs of the form (A, B) that tell...原创 2019-09-05 23:38:04 · 223 阅读 · 1 评论