摘要:
点击查看折叠代码块 //Zeller公式 /* 输入一个日期,计算这天是星期几 */ #include <bits/stdc++.h> using namespace std; int getId(int y, int m, int d) { if (m < 3) {y --; m += 12;} 阅读全文
posted @ 2020-07-28 20:39
wsl_lld
阅读(146)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 /* C(n,m) % p = n!/(m! * (n-m)!) % p = n! % p * inv[m!] % p * inv[(n-m)!] % p 求出1-n的前缀积pre[1]--pre[n] 和 1-n的逆元的前缀积 pre_inv[1]--pre_inv[n] 则 阅读全文
posted @ 2020-07-28 20:38
wsl_lld
阅读(150)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<string> using namespace std; const int maxn=1e5+10; int a[maxn 阅读全文
posted @ 2020-07-28 20:37
wsl_lld
阅读(83)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 int read(){ int 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-48 阅读全文
posted @ 2020-07-28 20:36
wsl_lld
阅读(166)
评论(0)
推荐(0)
摘要:
P3381 【模板】最小费用最大流 添加了弧优化 点击查看折叠代码块 /* 最大流最小费用 费用为单位流量的费用 在最大流的前提下找最短路径即为最小费用 边权为当前边的流量乘以单位流量的费用 首先构建一个图用最短路算法来找到源点到各个点的最短距离 找到这个数据之后,我们就可以沿着最短路来进行增广, 阅读全文
posted @ 2020-07-28 20:35
wsl_lld
阅读(196)
评论(0)
推荐(0)
摘要:
增添了弧优化,bfs提前判断 点击查看折叠代码块 /* 时间复杂度: O(N*N*M) */ #include <bits/stdc++.h> #define DEBUG #define d1(x) std::cout << #x " = " << (x) << std::endl #define 阅读全文
posted @ 2020-07-28 20:34
wsl_lld
阅读(104)
评论(0)
推荐(0)
摘要:
模板:直接求一般图最大匹配: 同时求出match[i]表示与第i个节点匹配的点是哪一个 点击查看折叠代码块 #include <bits/stdc++.h> using namespace std; const int maxn=1010; const int inf=0x3f3f3f3f; typ 阅读全文
posted @ 2020-07-28 20:31
wsl_lld
阅读(183)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 /* 树的重心也叫树的质心。对于一棵树n个节点的无根树,找到一个点, 使得把树变成以该点为根的有根树时,最大子树的结点数最小。 换句话说,删除这个点后最大连通块(一定是树)的结点数最小。 性质: 1.树中所有点到某个点的距离和中,到重心的距离和是最小的(实际应用中经常用到此性质) 阅读全文
posted @ 2020-07-28 20:29
wsl_lld
阅读(170)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 /* 两次dfs 第一次定一个根找离他最远的点 然后以该点为根再找离他最远的点 参考:https://www.cnblogs.com/handsome-zyc/p/11237529.html */ #include <bits/stdc++.h> using namespace 阅读全文
posted @ 2020-07-28 20:27
wsl_lld
阅读(124)
评论(0)
推荐(0)
摘要:
图论:树上问题(LCA,树链剖分) 一.LCA(Least Common Ancestors):最近公共祖先 对于有根树T的两个结点u、v,最近公共祖先LCA(T,u,v)表示一个结点x,满足x是u和v的祖先且x的深度尽可能大。在这里,一个节点也可以是它自己的祖先 ——百度百科 求LCA的常用算法: 阅读全文
posted @ 2020-07-28 20:26
wsl_lld
阅读(375)
评论(0)
推荐(0)
摘要:
概念:带花树——用来求一般图最大匹配的算法,相比较二分图的最大匹配的匈牙利算法,带花树可以处理图中有奇环的情况,将奇环缩成一个点(算法中叫做一朵花),然后再类似于匈牙利算法通过找增广路来找这个图的最大匹配。 具体的算法介绍可以参考这个博客,讲的很详细,我这里具体讲两个例题: 1.1 or 2 2.h 阅读全文
posted @ 2020-07-28 20:22
wsl_lld
阅读(440)
评论(0)
推荐(0)
摘要:
更新: KM算法正确性的定理: 转载于:http://www.cnblogs.com/celia01/archive/2012/04/02/2430260.html 1、二分图中的相关概念: 定理:无向图G为二分图的充分必要条件是,G至少有两个顶点,且其所有回路的长度均为偶数。 1.匹配:对于一个给 阅读全文
posted @ 2020-07-28 20:20
wsl_lld
阅读(741)
评论(0)
推荐(0)
摘要:
模板: 二维单调队列维护二维区间最大值、最小值 点击查看折叠代码块 /* 二维单调队列可以维护区间的最大值,最小值 */ #include <bits/stdc++.h> using namespace std; typedef long long int LL; const int MAXN = 阅读全文
posted @ 2020-07-28 20:18
wsl_lld
阅读(108)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 #pragma GCC diagnostic error "-std=c++11" #pragma GCC target("avx") #pragma GCC optimize(2) #pragma GCC optimize(3,"Ofast","inline") #pragma 阅读全文
posted @ 2020-07-28 20:16
wsl_lld
阅读(117)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 /* 树链剖分——重链剖分 可以求LCA 用线段树可以在树上维护区间最值、求区间和、求子树和等 */ #include <bits/stdc++.h> using namespace std; const int maxn=1e5+10; struct node{ int v,n 阅读全文
posted @ 2020-07-28 20:15
wsl_lld
阅读(117)
评论(0)
推荐(0)
摘要:
邻接矩阵: 点击查看折叠代码块 int n,m;//V1中的点数,V2中的点数 bool used[MAXN]; int line[MAXN][MAXN];//line != 0 表示存在这条边 int girl[MAXN]; bool find(int x){//递归过程 for (int j=1 阅读全文
posted @ 2020-07-28 20:13
wsl_lld
阅读(129)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 /* 时间复杂度: O(N*M*M) */ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int inf=0x3f3f3f3f; const int maxn=210; cons 阅读全文
posted @ 2020-07-28 20:12
wsl_lld
阅读(91)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 /* 二分图最大匹配,网络流最大流 左边为n个点,编号从 1 n 右边为m个点 编号从 n+1 n+m 建立超级源点0和超级汇点n+m+1 */ #include <bits/stdc++.h> using namespace std; const int maxn=510; c 阅读全文
posted @ 2020-07-28 20:11
wsl_lld
阅读(411)
评论(0)
推荐(0)
摘要:
点击查看代码块 #include <bits/stdc++.h> using namespace std; #define ll long long const int mode=1e9+7; int n; ll k; struct Matrix{ ll a[110][110];//一定要用long 阅读全文
posted @ 2020-07-28 20:09
wsl_lld
阅读(86)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 #include <bits/stdc++.h> using namespace std; const int maxn=1e5+10; typedef long long ll; int n; ll a[maxn],b[maxn],c[maxn]; ll Mul = 1; ll 阅读全文
posted @ 2020-07-28 20:08
wsl_lld
阅读(73)
评论(0)
推荐(0)
摘要:
1.线性求逆元 点击查看折叠代码块 typedef long long ll int n; int mode; ll inv[maxn]; void init(int mode){//线性求逆元 inv[0]=inv[1]=1; for (int i=2;i<maxn;i++){ inv[i] = 阅读全文
posted @ 2020-07-28 20:07
wsl_lld
阅读(253)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 int prim[Maxn],cnt,mu[Maxn],phi[Maxn]; bool vis[Maxn]; void Get(int n){ mu[1] = phi[1] = 1; for(int i=2;i<=n;i++) { if( !vis[i] ) prim[++cnt 阅读全文
posted @ 2020-07-28 20:03
wsl_lld
阅读(70)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);} void exgcd(ll a,ll b,ll &x,ll &y){ if(!b){x=1;y=0;} else{ exgcd(b,a%b,x,y); ll temp = x; x=y; y=t 阅读全文
posted @ 2020-07-28 20:02
wsl_lld
阅读(35)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 /* 二维树状数组+差分容斥 */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=1e3+10; 阅读全文
posted @ 2020-07-28 20:00
wsl_lld
阅读(81)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 int lowbit(int x){ return x & -x; } void update(int x,int v){ while(x<=n){ c[x]+=v; x+=lowbit(x); } } int query(int x){ int ret=0; while(x){ 阅读全文
posted @ 2020-07-28 19:59
wsl_lld
阅读(43)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 /* 将某区间每一个数乘上 x 将某区间每一个数加上 x 求出某区间每一个数的和 假设区间一次方和为Sum1 现在要求区间二次方和和三次方...n次方和 设区间一次方和Sum1 = a+b+c+d+... 则区间二次方和为Sum2 = a^2+b^2+c^2+d^2+... 区间 阅读全文
posted @ 2020-07-28 19:58
wsl_lld
阅读(240)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 /* 矩形面积 */ #include <bits/stdc++.h> #define ed end() #define bg begin() #define mkp make_pair #define pb push_back #define v(T) vector<T> #d 阅读全文
posted @ 2020-07-28 19:56
wsl_lld
阅读(117)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 /* 线段树维护区间最长连续子序列 */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=5e4+1 阅读全文
posted @ 2020-07-28 19:55
wsl_lld
阅读(211)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 //两多边形面积交,并模板 //输入n,n个点逆时针输入 //输入m,m个点逆时针输入 #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> u 阅读全文
posted @ 2020-07-28 19:53
wsl_lld
阅读(173)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 /* Str :需要处理的字符串(长度为Len) Suffix[i] :Str下标为i ~ Len的连续子串(即后缀) Rank[i] : Suffix[i]在所有后缀中的排名 SA[i] : 满足Suffix[SA[1]] < Suffix[SA[2]] …… < Suffix 阅读全文
posted @ 2020-07-28 19:51
wsl_lld
阅读(73)
评论(0)
推荐(0)
摘要:
带权并查集 点击查看折叠代码块 /* 给出一个区间的长度 N,及 M 个子区间和, 形如:x y z, 表示 子区间 [x, y] 的和为 z 如果一个“子区间和”与前面的“子区间和”冲突,即为错误(而且这个“子区间和”将在接下来的判断中被忽略)。 求总错误个数。 带权并查集 */ #include 阅读全文
posted @ 2020-07-28 19:49
wsl_lld
阅读(155)
评论(0)
推荐(0)
摘要:
点击查看折叠代码块 /* LCA(最近公共祖先)模板 倍增LCA */ #include <bits/stdc++.h> using namespace std; const int maxn=5e5+10; int fa[maxn][30]; int n,m,s; int head[maxn],c 阅读全文
posted @ 2020-07-28 19:46
wsl_lld
阅读(73)
评论(0)
推荐(0)
摘要:
分层图的应用范围: 比如最短路、网络流等,题目对边的权值提供可选的操作,比如可以将一定数量的边权减半,在此基础上求解最优解。 分层图的构建步骤可以描述为: 1、先将图复制成 k+1 份 (0 ~ k) 2、对于图中的每一条边 <u,v> 从 ui 到 vi+1 建立与题目所给操作相对应的边(i=0, 阅读全文
posted @ 2020-07-28 19:06
wsl_lld
阅读(468)
评论(0)
推荐(0)

浙公网安备 33010602011771号