My acm模板
Dilly__dally
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【模板】带权并查集 HDU 3038
具体学习参考https://blog.csdn.net/sunmaoxiang/article/details/80959300#commentBox 这篇博客也是我觉得比较好理解的方法——向量法,具体体现在代码。 hdu 3038 区间和悖论问题 假如说区间【fx,x】是之前建立的区间,他们之间和为sum[x],fx和x的联系可以用集合来存储,同理【fy,y】也是如此。当给出了一个新的...原创 2018-11-25 21:51:03 · 531 阅读 · 0 评论 -
【模板】线性筛
本文只讲素数筛。 #include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define ll long long const int maxn=200005; const double eps=1e-8; const double PI = acos(-1.0); #define lowbit(x) ...原创 2018-09-02 11:20:45 · 760 阅读 · 0 评论 -
【模板】树的重心(POJ1665)
题意:找重心和最大子树的节点数。 #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <vector> #include <iostream> using namespace std; int ...原创 2018-09-01 23:57:20 · 304 阅读 · 0 评论 -
【模板】tarjan(强连通+缩点)
具体学习参考https://blog.csdn.net/qq_34374664/article/details/77488976 /* * Tarjan 算法 * 复杂度 O(N+M) */ #include<bits/stdc++.h> using namespace std; const int MAXN = 20010;//点数 const int MAXM = 50010;...原创 2018-08-29 23:56:55 · 255 阅读 · 0 评论 -
【模板】判定二分图(染色)
判定一个图是否为二分图 从其中一个定点开始,将跟它邻接的点染成与其不同的颜色,最后如果邻接的点有相同颜色,则说明不是二分图,每次用bfs遍历即可。 #include <queue> #include <cstring> #include <iostream> using namespace std; const int N = 999;...原创 2018-08-29 09:24:42 · 426 阅读 · 0 评论 -
【模板】计算几何之二维几何
点 : // 计算几何模板 #include<bits/stdc++.h> using namespace std; const double eps = 1e-8; const double inf = 1e20; const double pi = acos( -1.0); const int maxp = 1010; //Compares a double to zero i...原创 2018-08-31 23:56:57 · 265 阅读 · 0 评论 -
KMP模板
/* next[] 的含义:x[i-next[i]...i-1]=x[0...next[i]-1] next[i] 为满足 x[i-z...i-1]=x[0...z-1] 的最大 z 值(就是 x 的自身匹配) */ void kmp_pre(char x[],int m,int next[]) { int i,j; j=next[0]= - 1; i=0; w...原创 2018-08-28 20:01:18 · 154 阅读 · 0 评论 -
【模板】树的直径(树的最长路)
具体学习参考https://blog.csdn.net/qq_32400847/article/details/51469917 #include<queue> #include<vector> #include<cstdio> #include<cstring> #include<iostream> #include<algo...原创 2018-08-30 23:33:16 · 252 阅读 · 0 评论 -
【模板】最短路之Dijkstra算法(堆优化)
具体学习参考https://blog.csdn.net/qq_35644234/article/details/60870719#commentBox 模板题HDU2544。 O(n^2) //Dijkstra 单源最短路 //权值必须是非负 /* * 单源最短路径,Dijkstra 算法,邻接矩阵形式,复杂度为O(n^2) * 求出源 beg 到所有点的最短路径,传入图的顶点数,和邻接矩...原创 2018-09-03 00:35:13 · 1179 阅读 · 0 评论 -
【模板】差分约束
具体学习参考https://blog.csdn.net/consciousman/article/details/53812818 https://blog.csdn.net/my_sunshine26/article/details/72849441原创 2018-09-11 19:58:31 · 307 阅读 · 0 评论 -
【模板】树状数组求逆序对
具体学习参考https://blog.csdn.net/ssimple_y/article/details/53744096 #include<bits/stdc++.h> using namespace std; const int N=2e5+5; ll p,a[N],sum[N],s[N]; int n; int lowbit(int i) { ...原创 2018-09-21 19:37:21 · 242 阅读 · 0 评论 -
【模板】离散化
使用STL算法离散化: 思路:先排序,再删除重复元素,然后就是索引元素离散化后对应的值。 假定待离散化的序列为a[n],b[n]是序列a[n]的一个副本,则对应以上三步为: sort(sub_a,sub_a+n); int size=unique(sub_a,sub_a+n)-sub_a;//size为离散化后元素个数 for(i=0;i<n;i++) a[i]=lower_bou...原创 2018-09-20 08:06:17 · 288 阅读 · 0 评论 -
【模板】康拓展开+逆康拓展开
具体学习参考https://blog.csdn.net/lttree/article/details/24798653 康拓展开: int fac[] = {1,1,2,6,24,120,720,5040,40320}; //i的阶乘为fac[i] // 康托展开-> 表示数字a是 a的全排列中从小到大排,排第几 // n表示1~n个数 a数组表示数字。 int kangtuo(i...原创 2018-09-15 00:02:46 · 322 阅读 · 0 评论 -
【模板】莫比乌斯函数
#include<bits/stdc++.h> using namespace std; const int MAXN = 1000000; bool check[MAXN+10]; int prime[MAXN+10]; int mu[MAXN+10]; void Mobius() { memset(check,false,sizeof(check)); mu[1]...原创 2018-09-24 11:19:45 · 401 阅读 · 0 评论 -
ACM入门之数学
一、数论 1.唯一分解定理: 题目:[lightoj1341](https://vjudge.net/contest/234388#problem/G), 题解:点击打开链接 [POJ1730](https://vjudge.net/contest/234388#problem/F) 题解:点击打开链接 2.Eratosthenes筛法: 埃氏筛素数: int m=sq...原创 2018-09-19 10:08:35 · 520 阅读 · 0 评论 -
【模板】数论之因子数问题
目前有如下问题: N的正因数个数 N的全体正因数之和 求1到n的因子和的和 求1到n的因子个数的和 具体参考https://blog.csdn.net/Hpuer_Random/article/details/81229214...原创 2018-09-18 17:08:14 · 322 阅读 · 0 评论 -
【模板】最短路之floyd
具体学习参考https://www.cnblogs.com/ECJTUACM-873284962/p/6995648.html #include<bits/stdc++.h> using namespace std; int main() { int e[10][10],k,i,j,n,m,t1,t2,t3; int inf=99999999; //用inf(inf...原创 2018-09-10 22:50:26 · 192 阅读 · 0 评论 -
【模板】最短路之SPFA
具体学习参考https://blog.csdn.net/qq_35644234/article/details/61614581 主要用于负权(无负权环)的最短路。 /* * 单源最短路 SPFA * 时间复杂度 0(kE) * 这个是队列实现,有时候改成栈实现会更加快,很容易修改 * 这个复杂度是不定的 */ #include<bits/stdc++.h> using name...原创 2018-09-10 21:30:25 · 256 阅读 · 0 评论 -
排列数和组合数
//组合数C(n,k) ll C(ll n,ll k) { if(2*k>n) k=n-k; ll s=1; for(ll i=1,j=n; i<=k; i++,j--) s=s*j/i; return s; } //排列数A(n,r) ll A(ll n,ll r) { ll sum=1; for(ll i =0;i&...原创 2018-08-27 16:24:42 · 718 阅读 · 0 评论 -
AC自动机模板(hdu2222)
具体学习参考https://blog.csdn.net/creatorx/article/details/71100840 模板来自kuangbin大神,HDU2222模板题 //====================== // HDU 2222 // 求目标串中出现了几个模式串 //==================== #include<bits/stdc++.h> us...原创 2018-08-20 14:13:54 · 208 阅读 · 0 评论 -
链式前向星模板
#include <stdio.h> #include <string.h> // 最大顶点数 const int V = 100000; // 最大边数 const int E = 100000; // 边结构体的定义 struct Edge { int to; // 表示这条边的另外一个顶点 int next; // 指...原创 2018-08-26 23:21:03 · 198 阅读 · 0 评论 -
莫比乌斯函数模板
const int MAXN = 1000000; bool check[MAXN+10]; int prime[MAXN+10]; int mu[MAXN+10]; void Moblus() { memset(check,false,sizeof(check)); mu[1] = 1; int tot = 0; for(int i = 2; i <= M...原创 2018-07-18 01:08:40 · 245 阅读 · 0 评论 -
【模板】逆元
扩欧法: ll kgcd(ll a,ll b,ll &x,ll &y)//扩欧 { if(!b) { x=1;y=0;return a; } ll t=kgcd(g,a%b,y,x); y-=a/b*x; return t; } ll niyuan(ll a,ll p) { ll x,y; kgc...原创 2018-07-16 11:36:47 · 281 阅读 · 0 评论 -
快速幂模板
快速幂求a^b: ll qpow(ll a,ll b) { ll t=1; while(b) { if(b % 2) { t*=a; b--; } a*=a; b/=2; } return t; } 快速幂求a^b后y位: ...原创 2018-06-07 21:10:31 · 242 阅读 · 0 评论 -
拓扑排序模板
/*==================================================*\ | topoSort -- 使用dfs | 使用dfs难以保证topo结果为最小的顺序 \*==================================================*/ int n, m, a, b, G[maxn][maxn]; ...原创 2018-04-30 00:28:27 · 166 阅读 · 0 评论 -
背包模板(01、完全、多重)
#include <stdio.h> #include <string.h> int max(int a, int b){ if (a > b)return a; return b; } #define maxn 100005 int c[maxn], w[maxn], num[maxn];//c:费用 w:价值 num:数量 int dp[maxn]; ...转载 2018-05-19 15:44:04 · 246 阅读 · 0 评论 -
八数码(哈希表判重)
#include<iostream> #include<cstring> #include<stack> #include<cstdio> using namespace std; const int maxn=1000000;//状态最大不超过9!,这里设置大一点 int dx[]={-1,1,0,0}; int dy[]={0,0,-1,1}...转载 2018-05-05 19:33:59 · 513 阅读 · 0 评论 -
最小生成树模板
具体学习参考https://blog.csdn.net/gettogetto/article/details/53216951 prim算法(稠密图): /* *O(n^2) * Prim 求 MST * 耗费矩阵 cost[][],标号从 0 开始,0 ∼ n-1 * 返回最小生成树的权值,返回 -1 表示原图不连通 */ bool vis[maxn]; int lowc[maxn]; i...原创 2018-04-25 19:09:37 · 172 阅读 · 0 评论 -
欧拉回路
什么是欧拉路径?在图上用一种走法经过所有的边一次且只有一次的路径叫做欧拉路径。即一笔画。如果这条路径的起点和终点重合,那么就是欧拉回路。如何判断图是否有欧拉回路或者欧拉路径?无向图:因为欧拉路径中,除了起点与终点以外,任意点的“进”“出”次数相等,所以除了两个点为奇点(度数为奇数的点)(终点和起点)以外,其它点的度数均为偶数。如果是欧拉回路,奇点的个数应该为0。有向图:欧拉路径中,最多只有两个点的...原创 2018-04-30 10:01:21 · 240 阅读 · 0 评论 -
二叉树重构(知后序中序求前序)
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define ll long long #define fo freopen("in.txt","r",stdin) #define fc fclose(stdin) #define fu0(i,n) for(i=0;i<n;i++) #de...原创 2018-07-19 17:27:54 · 277 阅读 · 0 评论 -
Miller-Rabin测试素数模板
ll qpow(ll a,ll b,ll M) //快速幂 { ll ans =1; while(b) { if(b&1) ans*=a;ans%=M; a*=a;a%=M;b>>=1; } return ans; } bool MillerRabinTest(ll x,ll n)/...原创 2018-07-14 15:31:10 · 352 阅读 · 0 评论 -
字典树(Trie)模板
字典树具体学习参考https://www.cnblogs.com/TheRoadToTheGold/p/6290732.html 查找字符串是否出现 /* trie tree的储存方式:将字母储存在边上,边的节点连接与它相连的字母 trie[rt][x]=tot:rt是上个节点编号,x是字母,tot是下个节点编号 */ #include<cstdio> #includ...原创 2018-08-15 18:08:22 · 243 阅读 · 0 评论 -
高斯消元模板
学习参考https://blog.csdn.net/pengwill97/article/details/77200372 浮点数: #define eps 1e − 9 const int MAXN=220; double a[MAXN][MAXN],x[MAXN];//方程的左边的矩阵和等式右边的值, 求解之后 x存的就是结果 int equ,var;//方程数和未知数个数 /* *...原创 2018-08-18 14:29:15 · 213 阅读 · 0 评论 -
并查集模板
int pre[maxn]; void init() { for(int i=0;i<maxn;i++) { pre[i]=i; } } int Find(int x) { int p=x,tmp; while(x!=pre[x]) x=pre[x]; while(p!=x) { tmp...原创 2018-08-12 21:54:32 · 227 阅读 · 1 评论 -
强连通分量(Kosaraju算法)
算法思想: 在一个有向图中,我们一定可以找到这样一个合理顺序,使得我们只需要按照这个顺序进行dfs遍历,那么每一次的dfs就可以使我们得到一个scc。合理顺序参考https://www.cnblogs.com/nullzx/p/6437926.html 经过简单的分析我们可以知道,那样的一个合理顺序就是scc图的拓扑顺序的逆序。 所以Kosaraju算法的核心思想就是如何找到scc图的拓扑顺...原创 2018-08-05 13:30:39 · 336 阅读 · 0 评论 -
割点与桥模板
算法: dfn【u】为dfs遍历中u是第几个被访问到的。 low【u】为该dfs u可以到达的访问时间最早的祖先的深度。 首先,对图进行一次dfs遍历,可以得到每个点的dfn和low。 考察所有点u和它在dfs树中的儿子节点s1,s2……sk。 (1)如果对于某个si,满足low[si]>=dfn[u],那么u是一个割点; (2)如果对于某个si,满足low[si]>dfn...原创 2018-08-04 21:36:15 · 210 阅读 · 0 评论 -
无向图的连通分量(DFS方法)
#include <stdio.h> #include <stdlib.h> #include <string.h> int mp[100][100]; int visit[100]; void dfs(int x,int n) { int i; visit[x]=1; for(i=1;i<=n;i++) { if(...原创 2018-08-05 13:07:37 · 2276 阅读 · 0 评论 -
树状数组模板
讲解:传送门 const int maxn=50005; const double eps=1e-8; int tree[maxn]; inline int lowbit(int x) { return x&-x; } void add(int x,int value) //输入数据时,需要调用此函数加到tree[]里面 { for(int i=x;i<=maxn...原创 2018-07-20 16:02:29 · 167 阅读 · 0 评论 -
二叉堆
堆是完全二叉树,左孩子是2i,右孩子是2i+1。 用途:堆排序,实现优先队列 插入删除查找时间复杂度:O(logn) 堆排序复杂度:O(nlogn) /**** **** **** **** **** **** * Function Name : 二叉堆 * Description : 父结点的键值总是大於或等於任何一个子节点的键值 * 便於寻找父节点和子节点 **** **** ***...原创 2018-07-20 12:30:35 · 278 阅读 · 0 评论 -
大数任意进制转换模板
第一种(大数)#include<iostream> #include<cstring> using namespace std; const int MAXN = 1000; int t[MAXN], A[MAXN]; char OldData[MAXN], NewData[MAXN]; // 转换前、后的数据 int olds, news; ...原创 2018-04-23 13:02:57 · 553 阅读 · 0 评论
分享