随笔分类 -  ACM——模板

摘要:#pragma comment(linker, "/STACK:102400000,102400000") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #defi... 阅读全文
posted @ 2016-08-23 15:25 chenhuan001 阅读(192) 评论(0) 推荐(0) 编辑
摘要:/* 幻方的计算: 计算任意阶数幻方的各行、各列、各条对角线上所有数的和的公式为:sum=n*(n^2+1)/2 n为阶数 幻方分为奇阶幻方和偶阶幻方 一、当n为奇数时称为奇阶幻方 1、Merzirac法生成奇阶幻方 在第一行居中的方格内放1,依次向右上方填入2、3、4…,如果右上方已有数字,则向下移一格继续填写。 ... 阅读全文
posted @ 2016-08-23 11:17 chenhuan001 阅读(687) 评论(0) 推荐(0) 编辑
摘要:#define N 100100/******************_单调队列模板_******************/ //基于单调队列功能的单一性:以limit为序查找在一定范围内的极值。 //复杂度:O(n) //用法: 创建的时候调用.init() // 插入队列:.push( Q_Node( KEY,LIMIT ) ); // 设置limit值:.setlimi... 阅读全文
posted @ 2016-08-17 21:46 chenhuan001 阅读(201) 评论(0) 推荐(0) 编辑
摘要:划分树:一般用于快速求区间[a,b]第k大的数。 阅读全文
posted @ 2016-08-10 11:29 chenhuan001 阅读(282) 评论(0) 推荐(0) 编辑
摘要:#include #include #include #define maxn 210 #define CL(a,num) memset((a),(num),sizeof(a)) #define iabs(x) ((x) > 0 ? (x) : -(x)) #define EPS 1e-8 using namespace std; int equ,var;//方程个数和自由元的个数 do... 阅读全文
posted @ 2016-08-09 22:51 chenhuan001 阅读(238) 评论(0) 推荐(0) 编辑
摘要:PS. 看了大神的题解,发现确实可以用m个未知数的高斯消元做。因为确定了第一行的情况,之后所有行的情况都可以根据第一行推。 这样复杂度直接变成O(m*m*m) 知道了是高斯消元后,其实只要稍加处理,就可以解决带模的情况。 1 是在进行矩阵行变化的时候,取模。 2 最后的除法用逆元。(因为a[i][i 阅读全文
posted @ 2016-08-04 01:13 chenhuan001 阅读(1456) 评论(0) 推荐(0) 编辑
摘要://组合数打表模板,适用于N<=3000 //c[i][j]表示从i个中选j个的选法。 long long C[N][N]; void get_C(int maxn) { C[0][0] = 1; for(int i=1;i<=maxn;i++) { C[i][0] = 1; for(int j=1;j<=i;j++) ... 阅读全文
posted @ 2016-07-27 22:07 chenhuan001 阅读(2032) 评论(0) 推荐(0) 编辑
摘要:代码量超少的求一些特别情况的mobus,复杂度O( nlog(n) ) 阅读全文
posted @ 2016-07-06 10:40 chenhuan001 阅读(199) 评论(0) 推荐(0) 编辑
摘要:2.LCA 在线建立rmq(nlog(n)) 查询(log(n)) 阅读全文
posted @ 2016-07-01 13:15 chenhuan001 阅读(205) 评论(0) 推荐(0) 编辑
摘要:一、概念 概念: 1.桥: 如果在图G中删去一条边e后,图G的连通分支数增加,即W(G-e)>W(G),则称边u为G的桥,又称割边或关节边。 2.割点:如果在图G中删去一个结点u后,图G的连通分枝数增加,即W(G-u)>W(G),则称结点u为G的割点,又称关节点。 3.点双连通分量:不含割点的连通子 阅读全文
posted @ 2016-04-02 17:23 chenhuan001 阅读(285) 评论(0) 推荐(0) 编辑
摘要://网络流SAP模板,复杂度O(N^2*M) //使用前调用init(源点,汇点,图中点的个数),然后调用add_edge()加边 //调用getflow得出最大流 #define N 55 #define M 500500 #define INF 0x3fffff struct Max_Flow { struct node { int to,w,next; ... 阅读全文
posted @ 2016-03-20 14:38 chenhuan001 阅读(312) 评论(0) 推荐(0) 编辑
摘要:类似于斜率优化的东西,果真CF的E以后才会考点算法啊。 感觉这种优化应该很常见,但这题直线只有第一象限的,但是插入,和查找操作是不变的,按极角排序后就可以直接用这个模板了。 #include <iostream> #include <stdio.h> #include <string.h> #inc 阅读全文
posted @ 2016-03-07 22:18 chenhuan001 阅读(858) 评论(0) 推荐(0) 编辑
摘要:void RMQ_init() { for(int i=1; i<=n; i++) dp[i][0]=s[i]; for(int j=1; (1<<j)<=n; j++) for(int i=1;i+(1<<j)-1<=n;i++) dp[i][j]=max(dp[i][j-1],dp[i+(1<< 阅读全文
posted @ 2016-03-04 20:28 chenhuan001 阅读(158) 评论(0) 推荐(0) 编辑
摘要:换了个模板。 O(n)复杂度求P串出现在T串中的所有位置。 void getFail(char* P, int* f) { int m = strlen(P); f[0] = 0; f[1] = 0; for(int i = 1; i < m; i++) { int j = f[i]; while( 阅读全文
posted @ 2016-03-04 08:40 chenhuan001 阅读(155) 评论(0) 推荐(0) 编辑
摘要:扩展KMP指的是 对于给出的串S和T,以O(n)的时间求出。 对于所有0<=i<len(S),S(i,i+1,...,len(s)-1)与T的最长前缀长度。 next[i]为满足B[i..i+z-1]==B[0..z-1]的最大的z值。 以下是模板: #include <iostream> #inc 阅读全文
posted @ 2016-03-04 00:40 chenhuan001 阅读(309) 评论(0) 推荐(0) 编辑
摘要:偶然碰到这个算法,学习下。 这样可以在O(n^3)的时间内找出非二分图的最大匹配。 #include <cstdio> #include <algorithm> #include <set> #include <vector> using namespace std; const int NMax= 阅读全文
posted @ 2016-03-03 21:37 chenhuan001 阅读(382) 评论(0) 推荐(0) 编辑
摘要:1.普通素数筛选模板 最普通的方法。。。 2.快速素数筛选 这种方法经证明只需要2n的复杂度,但是因为有*,/,%等运算,所以只比一般素数筛选快3倍左右。 关于复杂度的证明,用整体的思路就很好证明,算法由一层循环O(n)再加上所有产生的合数,可以证明每个合数都会被产生一次且仅一次。 所以这个算法每一 阅读全文
posted @ 2016-03-01 17:20 chenhuan001 阅读(507) 评论(0) 推荐(0) 编辑
摘要:struct Binary_Index_tree { long long a[N]; void init() { memset(a,0,sizeof(a)); } //位运算 int lowbit(int x) { return x & (-x); } //修改x这个点,并把所有包含x点的所有点都进 阅读全文
posted @ 2016-01-28 12:26 chenhuan001 阅读(174) 评论(0) 推荐(0) 编辑
摘要://仅适合纯数字输入 int Scan() //输入外挂 { int res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch='0'&&ch9) Out(a/10); putchar(a%10+'0'); } //long long 输... 阅读全文
posted @ 2016-01-28 12:05 chenhuan001 阅读(306) 评论(0) 推荐(0) 编辑
摘要://seed 是大质数unsigned long long MurmurHash64B ( const void * key, int len, unsigned int seed ){ const unsigned int m = 0x5bd1e995; const int r = 2... 阅读全文
posted @ 2016-01-13 10:06 chenhuan001 阅读(711) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示