![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
KMP
皮得一1
这个作者很懒,什么都没留下…
展开
-
hust 1010 The Minimum Length(KMP求最小循环节)
最小循环节:http://www.cnblogs.com/jackge/archive/2013/01/05/2846006.html 代码 #include #include #define N 1000005 char str[N]; int next[N]; void getNext(int len) { int i=0,j=-1; next[原创 2015-10-31 22:25:33 · 436 阅读 · 0 评论 -
hdu 3336 Count the string(KMP+dp)
题意:将字符串的每个前缀作为模式串,字符串作为主串,求模式串在主串中出现的次数和。 #include #include #include using namespace std; #define MAXN 200005//字符串长度 #define MOD 10007 char s[MAXN]; int dp[MAXN]; int _next[MAXN]; void GetNext(ch原创 2016-01-23 20:23:13 · 332 阅读 · 0 评论 -
hdu 2594 Simpsons’ Hidden Talents(KMP)
题意:给定两个字符串s1,s2,找出s1的前缀和s2的后缀的公共长度。 思路:合并字符串后求next数组。 #include #include #include #include using namespace std; char s1[100010],s2[50005]; int _next[100010]; void get_next(char a[]) { int i=-1,原创 2016-01-23 19:09:23 · 345 阅读 · 0 评论 -
poj 2406 Power Strings(KMP求最大循环次数)
题意:在字符串中求出最大的循环次数。 #include #include #include using namespace std; const int M = 1000010; int nxt[M]; char T[M]; int n,m; int ans; void getnext(){ int j, k; j = 0; k = -1; nxt[0] = -1;原创 2016-01-23 18:22:48 · 414 阅读 · 0 评论 -
hdu 1358 Period(KMP循环节)
题意:给定一个字符串,求出所有循环的前缀串,输出前缀串的长度和循环的次数(大于一才算循环串)。 #include #include #include using namespace std; #define MAXN 1000005//字符串长度 char str[MAXN]; int _next[MAXN]; void GetNext(char t[]) //求next数组 {原创 2016-01-23 18:10:32 · 367 阅读 · 0 评论 -
hdu 3746 Cyclic Nacklace(KMP求循环节)
题目大意: 给你一个字符串,要求将字符串的全部字符最少循环2次需要添加的字符数。 例子: abcabc 已经循环2次,添加数为0。 abcac 没有循环2次,添加字符abcac。数目为5。 abcabcab 已经循环过2次,但第三次不完整,需要添加数为1。 循环节知识:http://www.cnblogs.com/jackge/archive/2013/01/05/2846006.原创 2016-01-23 18:00:17 · 318 阅读 · 0 评论 -
hdu 2087 剪花布条(KMP)
题意:KMP算法统计主串中包含模式串的个数,模式串在主串中不可重叠。 如:s="aaaaaa" t="aa" 则t在s中出现3次,而不是5次。需在每次成功匹配后t的指针重新指向从串首 #include #include #include using namespace std; #define MAXN 10005//字符串长度 char W[MAXN]; char T[100000原创 2016-01-23 17:05:55 · 286 阅读 · 0 评论 -
hdu 1686 Oulipo(KMP)
题意:KMP算法查找模式串在主串中出现的次数。 #include #include #include using namespace std; #define MAXN 10005//字符串长度 char W[MAXN]; char T[1000005]; int _next[MAXN]; void GetNext(char t[]) //求next数组 { int j,k,le原创 2016-01-23 16:53:37 · 301 阅读 · 0 评论 -
hdu 1711 Number Sequence(KMP算法)
题意:KMP匹配,返回模式串第一次与主串匹配的位置。 #include #include #include using namespace std; #define MAXN 10005//字符串长度 int a[1000005]; int b[MAXN]; int _next[MAXN]; void GetNext(int t[],int M) //求next数组 { int原创 2016-01-23 16:51:06 · 321 阅读 · 0 评论 -
hdu 4763 Theme Section(KMP)
题意:在一个字符串中,找出一个最长的子串,该子串满足条件:在串的开头、中间和结尾分别出现一次且不能交叉重叠。 思路:KMP求出next,确定串的前缀和后缀的公共长度,再在中间部分查找是否存在满足条件的子串。 将串分为3段进行查找,如图, ----------------- ---------------------- i ------------------ 其原创 2016-01-23 22:56:12 · 402 阅读 · 0 评论