随笔分类 -  算法模板

摘要:后缀数组 DA(倍增)算法求 SA[N] 与 Rank[N] (时间O(NlogN),空间O(N))sa[i] : 表示 排在第i位的后缀 起始下标rank[i] : 表示后缀 suffix(i)排在第几height[i] : 表示 sa[i-1] 与 sa[i] 的LCP 值h[i]: 表示 suffix(i)与其排名前一位的 LCP值const int N = int(2e5)+10;int cmp(int *r,int a,int b,int l){ return (r[a]==r[b]) && (r[a+l]==r[b+l]);}// 用于比较第一关键字与第二关键字,/ 阅读全文
posted @ 2013-08-02 21:51 yefeng1627 阅读(4957) 评论(1) 推荐(1)
摘要:#include#include#include#include#includeusing namespace std;const int N = 2010;const int M = 10010;typedef long long LL;const int SIZE = 100003;const int SEED = 13333;struct Node{ LL key; int type; Node *next; Node *set(LL _key,Node *_next ){ key = _key; next = _next; type = -1; ... 阅读全文
posted @ 2013-07-31 17:51 yefeng1627 阅读(407) 评论(0) 推荐(0)
摘要:图的连通性dfn[u]: 表示节点u的搜索优先级low[u]: 表示节点u,通过其本身或其子节点能到达的最小有搜索优先级low[u] = Min{ 1. dfn[u] 其本身搜索优先级 2. Min{ low[v] } 其子节点v能到达的最小优先级 3. Min( dfn[v] ) 其通过回边(u,v),其中v为u的祖先节点,的优先级}一无向图1. 割点又名关键点,若删除该点与其发出的边.则整个图不连通.当前顶点u是一个关键点的充要条件是:1. 若顶点U是根,则其必定包含两个以上的子节点. (因为若只有一个.删除了U之后,图仍然连通)2. 若顶点U不是根,... 阅读全文
posted @ 2013-07-26 13:49 yefeng1627 阅读(1077) 评论(0) 推荐(0)
摘要:#include#include#include#include#includeusing namespace std;const double esp = 1e-8;#define Fact(x) ((x)*(x))//一般图匹配带花树const int MaxN = 111;int N;bool Graph[MaxN][MaxN];int Match[MaxN];bool InQueue[MaxN], InPath[MaxN], InBlossom[MaxN];int Head, Tail;int Queue[MaxN];int Start, Finish;int NewBase;int 阅读全文
posted @ 2013-07-24 17:27 yefeng1627 阅读(883) 评论(0) 推荐(0)
摘要:1 // Code From ftiasch 2 #include <cstdio> 3 #include <cstring> 4 #include <climits> 5 #include <algorithm> 6 using namespace std; 7 8 const int N = 111111; 9 const int INF = 1000000000; 10 11 struct Node { 12 int minimum; 13 Node *left, *right; 14 15 Node(int m, Node *l, N.. 阅读全文
posted @ 2013-05-30 22:11 yefeng1627 阅读(424) 评论(0) 推荐(0)
摘要:邻接矩阵: 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #define MIN(a,b) (a)<(b)?(a):(b) 5 const int M = 110; 6 const int inf = 0x3fffffff; 7 int n, m, A[1010], pre[1010]; 8 int remain[M][M], h[M], vh[M], S, T, N;39 int DFS( int u, int flow ) 40 {41 if( u == T ) re 阅读全文
posted @ 2013-05-25 10:23 yefeng1627 阅读(337) 评论(0) 推荐(0)
摘要:全名: Aho-Corasick 自动机, 类似 Trie + next函数写法: 动态 / 静态, 个人比较偏向与静态内容: 网上一大堆,我是看的 LRJ新版白书214页静态模板:// Aho-Corasick#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<queue>#include<algorithm>using namespace std;#define Clear(x) memset(x,0,sizeof(x)) 阅读全文
posted @ 2013-05-23 11:43 yefeng1627 阅读(946) 评论(0) 推荐(0)
摘要:// 原串最大长度N// 返回最大回文字串 res#include<cstdio>#include<cstring>#include<cstdlib>#include<string>#include<algorithm>using namespace std;const int N = 1024;int rid[N<<2];string manacher(char *s){ string t, res; int L = strlen(s); // init t += '?'; for(int i = 0; 阅读全文
posted @ 2013-05-20 12:00 yefeng1627 阅读(234) 评论(0) 推荐(0)
摘要:kmp含义 克努斯-莫里斯-普拉特算法,一种字符串查找算法。 字符串算法主要是用于主串 S( s1,s2,s3,...,sn ), 模式串T( t1,t2,...,tm ), 之间的匹配问题. 相对与模式匹配O(n^2)而言:当 Si != Tj 失配时, 主串下标i不回溯, 而是将模式串下标j回溯到合适的地方,再继续比较 Tj ,Si.时间复杂度极端情况是 O(N*M), 但是一般情况下总能保证O(N+M). 假定串 S( i-j+1, i ) 与 模式串 T( 1, j ) 匹配时, Si != Tj 不匹配,此时需j最短回溯到 k, 则存在 T(1,k-1) = T( j-k... 阅读全文
posted @ 2013-04-28 20:41 yefeng1627 阅读(1256) 评论(0) 推荐(0)
摘要:#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>using namespace std;const int inf = 0x3f3f3f3f;const int N = 101;int n, m; struct Matrix{ int mat[N][N]; Matrix(){ memset(mat,0,sizeof(mat)); } void input(){ for(int i = 0; i < m; i++) for(i... 阅读全文
posted @ 2013-04-22 22:48 yefeng1627 阅读(223) 评论(0) 推荐(0)
摘要:1 namespace MappingBinaryHeap{ 2 /* 3 DS: 4 Datastructure to show the value 5 Heap: 6 1.Ds:value 7 2.idx:index 8 pos: 9 The position for each index10 len:11 The volum n of heap12 hh:13 heap14 Push:15 insert an element16... 阅读全文
posted @ 2013-04-12 15:39 yefeng1627 阅读(316) 评论(0) 推荐(0)
摘要:Splay 概念文章:http://blog.csdn.net/naivebaby/article/details/1357734叉姐 数组实现:https://github.com/ftiasch/mithril/blob/master/2012-10-24/I.cpp#L43Vani 指针实现:https://github.com/Azure-Vani/acm-icpc/blob/master/spoj/SEQ2.cpphdu 1890 写法:http://blog.csdn.net/fp_hzq/article/details/8087431HH splay写法:http://www.n 阅读全文
posted @ 2013-04-07 21:59 yefeng1627 阅读(1515) 评论(0) 推荐(0)
摘要:int gcd( int a, int b ){ if( a == 0 ) return b; if( b == 0 ) return a; if( a%2 == 0 && b%2 == 0 ) return 2*gcd( a/2, b/2 ); else if( a%2 == 0 ) return gcd( a/2, b ); else if( b%2 == 0 ) return gcd( a, b/2 ); else return gcd( abs(a-b), min(a,b) );... 阅读全文
posted @ 2013-04-07 13:18 yefeng1627 阅读(119) 评论(0) 推荐(0)
摘要:#include<cstdio>#include<cstring>#define N 1010bool flag[N], a[N][N];int ans, cnt[N], group[N], n, vis[N];// 最大团: V中取K个顶点,两点间相互连接// 最大独立集: V中取K个顶点,两点间不连接 // 最大团数量 = 补图中最大独立集数 bool dfs( int u, int pos ){ int i, j; for( i = u+1; i <= n; i++){ if( cnt[i]+pos <= ans ) return 0; if( a.. 阅读全文
posted @ 2013-03-31 13:18 yefeng1627 阅读(223) 评论(1) 推荐(0)
摘要:在这里记录下比较有用的计算几何模板,以便于以后自己查找,持续更新坐标点数据类型struct Point{ double x, y; };已知三点,求外界圆心Point Cross( Point A, Point B, Point c ){ Point o; double a1 = B.x - A.x, b1 = B.y - A.y, c1 = a1*a1+b1*b1; double a2 = C.x - A.x, b2 = C.y - A.y, c2 = a2*a2+b2*b2; double d = a1 * b2 - a2 * b1; // det( AB,... 阅读全文
posted @ 2013-03-29 16:29 yefeng1627 阅读(136) 评论(0) 推荐(0)
摘要:问题:模线性同余方程组: x = a1 ( mod n1 ) x = a2 ( mod n2 ) .... x = ak ( mod nk )给定 A ( a1, a2 , ... , ak ) , N ( n1, n2, ..., nk ) 求 X 。通常分为两种 一, ( Ni, Nj ) 之间两两互质 二, ( Ni, Nj ) 之间不都互质一 ( Ni, Nj ) 之间两两互质 定理( 见算法导论 P874 ): 如果 n1, n2 , ... , nk 两两互质, n = n1*n2*..*nk ,则对任意整数 a1,a2,a3..,ak , 方程组 x =... 阅读全文
posted @ 2012-12-31 22:26 yefeng1627 阅读(2162) 评论(1) 推荐(1)

Launch CodeCogs Equation Editor