HDU 1686 & KMP】的更多相关文章

// hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; ; ; char T[MAX_N]; char p[MAX_M]; int f[MAX_M]; int n,m; void getfail(){ f[] = f[] = ; ;i&l…
题意: 求模板在匹配串所有子串中出现次数. SOL: 本题与普通kmp有一点不同,因为待匹配串中的模板串可能相互包含. 我们考虑正常的kmp是在怎么做的 i = 1 2 3 4 5 6 7 8 9 ……    A = a b a b a b a a b a b …    B = a b a b a c b     j = 1 2 3 4 5 6 7 i=j=6时两个字符串不同了,那么j要减小到上一个匹配的地方. 当匹配完了呢? 比如 i = 1 2 3 4 5 6   A= a z a z a…
题意: 求模式串W在母串T中出现的次数,各个匹配串中允许有重叠的部分. 分析: 一开始想不清楚当一次匹配完成时该怎么办,我还SB地让i回溯到某个位置上去. 后来仔细想想,完全不用,直接让模式串向前滑动,即 j = next[j] #include <iostream> #include <cstdio> #include <cstring> using namespace std; + ; + ; char W[maxn1], T[maxn2]; int next[ma…
题目大意:求模式串在主串中的出现次数. 题目思路:KMP模板题 #include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<stdio.h> #include<stdlib.h> #include<queue> #include<math.h> #include<map> #define INF…
题意: 求子串w在T中出现的次数. kmp算法详解:http://www.cnblogs.com/XDJjy/p/3871045.html #include <iostream> #include <cstring> #include <string> #include <cstdio> using namespace std; int lenp; int lens; void getnext(int *next, char *p) { , k = -; n…
HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book: Tout avait…
id=25191" target="_blank" style="color:blue; text-decoration:none">HDU - 1686 Oulipo Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u id=25191" class="login ui-button ui-widget ui-state-…
题意: 用两个字符串分别表示布条和图案,问能从该布条上剪出多少这样的图案. 分析: 毫无疑问这也是用KMP匹配,关键是一次匹配完成后,模式串应该向后滑动多少. 和上一题 HDU 1686 不同,两个图案肯定不能在母串中有交叉的部分,所以当匹配成功一次后,应当滑动整个模式串的长度. 和上一题比,代码几乎不变,只是 j = next[j]; 变为 j = 0; #include <cstdio> #include <cstring> + ; char p[maxn], q[maxn];…
Cyclic Nacklace HDU 3746 KMP 循环节 题意 给你一个字符串,然后在字符串的末尾添加最少的字符,使这个字符串经过首尾链接后是一个由循环节构成的环. 解题思路 next[len]-len的差即是循环部分的长度. 这个是重点.这个题目自己开始没有想明白,看的博客,推荐这个. 代码实现 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const i…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 分析:典型的KMP算法,统计字符串匹配的次数. 用Next数组压缩时间复杂度,要做一些修改. /*Oulipo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5769 Accepted Submission(s): 2322 Proble…