![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法模板
Tawn0000
游荡的IT!
展开
-
并查集——模板
int T,N,M;int f[100010*2];void init(){ for (int i = 1; i <= N; i++) f[i] = i,f[i+N] = i+N; return;}int find(int x){ if(x == f[x]) return x; else return f[x]...原创 2017-04-09 01:13:06 · 288 阅读 · 0 评论 -
最大流EK、Dinic、SAP三种算法模板
EK //Max_flow//@2018/05/02 Wednesday//EK algorithm [Edmonds Karp] O(V*E^2) O(v^2)//by Tawn#include <bits/stdc++.h>using namespace std;const int maxn = 1e3;const int INF = 0x3f3f3f3f;...原创 2018-09-23 21:57:32 · 485 阅读 · 0 评论 -
BTSP——HDU2224The shortest path
(Bitonic Traveling Salesman Problem ) 双调(欧几里得)旅行商问题 欧几里得旅行商问题是指在一个平面上有n个点,找出连接所有点的最短闭合路径的问题。这个问题虽然是一个求最短路的问题,但是其实和图论没什么很大关系,用的是动态规划的思想。J.L. Bentley 建议通过只考虑双调(Bitonic)路径来求得最短路径。双调路径是指从一个最左端的点出发,严格...原创 2018-03-10 11:49:06 · 1100 阅读 · 0 评论 -
二分图匹配——Hopcroft-Carp算法模板
Hopcroft-Carp算法讲解 (看了很多blog,这个写得比较详细)typedef long long LL;using namespace std;const int maxn = 3010;const int INF = 0x3f3f3f3f;bool g[maxn][maxn];bool vis[maxn];int dx[maxn],dy[maxn];int M...原创 2017-10-15 10:58:59 · 481 阅读 · 0 评论 -
二分图匹配——匈牙利算法模板
bool g[maxn][maxn];bool vis[maxn];int line[maxn];//寻找增广路O(VE)bool dfs(int u,int n){ for(int v = 0; v < n; v++) { if(g[u][v] && !vis[v]) { vis[v] = true;...原创 2017-10-15 10:52:28 · 489 阅读 · 0 评论 -
计算几何 —— 模板
#include<complex>#define sqr(x) ((x)*(x))#define LL long long#define INF 0x3f3f3f3fconst double PI = acos(-1.0);const double eps = 1e-8;#define maxm 210010#define maxn 110using namespace std;st原创 2017-11-08 20:09:10 · 244 阅读 · 0 评论 -
二分图匹配 判断是否为二分图 —— 模板
bool g[maxn][maxn];int col[maxn];//利用0,1染色,层序遍历,用同色则为falsebool bfs(int n){ memset(col,-1,sizeof(col)); for(int i = 0; i < n; i++) { if(col[i] != -1) continue; queue&...原创 2017-10-15 10:48:24 · 395 阅读 · 0 评论 -
hdu2176取(m堆)石子游戏 ——Nim 博弈
Nim博弈——hdu2176取(m堆)石子游戏AC code#include <iostream>#include <string>#include<cstring>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <map>const int maxn = 2e5 + 10;原创 2017-09-11 22:50:35 · 456 阅读 · 0 评论 -
hdu2177 —— 威佐夫博奕模板(胜利者操作)——hdu2177取(2堆)石子游戏
威佐夫博奕模板(胜利者操作)——hdu2177取(2堆)石子游戏AC code#include <iostream>#include <string>#include<cstring>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <map>const int maxn =原创 2017-09-11 21:42:44 · 285 阅读 · 0 评论 -
hdu1527取石子游戏——威佐夫博奕模板
威佐夫博奕模板——hdu1527取石子游戏解析: 1.https://baike.baidu.com/item/%E5%A8%81%E4%BD%90%E5%A4%AB%E5%8D%9A%E5%BC%88/19858256?fr=aladdin 2.http://blog.sina.com.cn/s/blog_a661ecd501017out.htmlAC code#include <iostre原创 2017-09-11 16:15:40 · 322 阅读 · 0 评论 -
线段树区间更新(2)(lazy)(区间都变为v)(序号从1开始)(O(logn))模板(hdu1698)
线段树区间更新模板AC code#include <iostream>#include <string>#include<cstring>#include <stdio.h>#include <cmath>#include <algorithm>#include <vector>#define y1 yy1#define y2 yy2const int maxn = 1 << 18原创 2017-09-07 21:39:55 · 330 阅读 · 1 评论 -
线段树区间更新(1)(区间同时加上x)模板(序号从0开始)O(logn)(poj3468)
线段树区间更新模板AC code#include <iostream>#include <string>#include<cstring>#include <stdio.h>#include <cmath>#include <algorithm>#include <vector>const int maxn = 1 << 17;const int MOD = 1e9 + 7;con原创 2017-09-06 23:40:46 · 304 阅读 · 0 评论 -
快速幂——模板
LL Qpow(LL a,LL b){ LL ans = 1; while(b)//用一个循环从右到左便利b的所有二进制位 { if(b&1)//判断此时b[i]的二进制位是否为1 { ans = (ans*a)%MOD;//乘到结果上,这里a是a^(2^原创 2017-08-17 21:54:38 · 304 阅读 · 0 评论 -
组合数C(m,n)——模板
LL C[maxn][maxn];void get_C(LL x){ C[0][0] = 1; for(int i=1;i<=x;i++) { C[i][0] = 1; for(int j=1;j<=i;j++) C[i][j] = (C[i-1][j]+原创 2017-08-17 21:51:33 · 1522 阅读 · 0 评论 -
BIT —— 模板
LL bit[maxn];LL sum(LL i){ LL s = 0; while(i > 0) { s += bit[i]; i -= i & -i; } return s;}void add(LL i, LL x){ while (i <= M) { bit[i] += x;原创 2017-04-25 15:47:26 · 424 阅读 · 0 评论 -
RMQ-ST模板
typedef long long LL;LL a[maxn];//a0 —— an-1LL n;LL N,M,K,T,t,q;LL d[maxn][18];LL gcd(LL a,LL b){ if (b==0) return a; else return gcd(b,a%b);}void predig(){ memset(d,0,sizeof(d))原创 2017-04-30 14:53:15 · 305 阅读 · 0 评论 -
Kruskal——模板
#include <iostream>#include <cstdio>#include <algorithm>#include <map>#include <set>#include <queue>#include <stack>#include <cstring>#i原创 2017-04-09 01:18:15 · 377 阅读 · 0 评论 -
最小费用最大流模板
#include <bits/stdc++.h>using namespace std;const int maxn = 100 + 100;const int maxm = 100 + 100;const int INF = 0x3f3f3f3f;typedef long long LL;typedef pair<int,int> P;//const ...原创 2018-09-25 16:03:48 · 246 阅读 · 0 评论