
KMP
文章平均质量分 62
不可不戒
这个作者很懒,什么都没留下…
展开
-
hdu1867 A + B for you again
#include #include #define MAXN 100005int next[MAXN];char str1[MAXN],str2[MAXN];void getNext(char *str){ int len=strlen(str); int i=0,j=-1; next[0]=-1; while(i<len) { if (j==-1||str[i]==原创 2013-07-14 13:18:16 · 772 阅读 · 0 评论 -
hdu4552 怪盗基德的挑战书
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4552题解:此题与hdu3336一样。见http://blog.youkuaiyun.com/lezg_bkbj/article/details/11020233#include #include #define MAXN 100002 #define MOD 256原创 2013-09-05 20:36:09 · 893 阅读 · 0 评论 -
hdu3336 Count the string
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=33366 a b a b a b ‘\0’下标i: 0 1 2 3 4 5 6Next: -1 0 0 1 2 3 4dp: 0 1 1 2 2 3 3dp[ 1 ]=原创 2013-09-03 21:55:34 · 802 阅读 · 0 评论 -
hdu3374 String Problem
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374题解:循环移位,找字典序最前的和字典序最后的下标标号,然后把次数也输出来。用最小表示法和最大表示法找到字典序最小和最大的字符串。用kmp计算出现的次数(最小循环周期)。//http://blog.youkuaiyun.com/coraline_m/article/details/983原创 2013-09-03 20:19:16 · 739 阅读 · 0 评论 -
hdu3746 Cyclic Nacklace (循环节)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746题解:将所给的字符串变成多个完整的循环(至少两个),然后给出最少需要添加的字符数。见算法KMP.#include #include #define MAXN 100001 char text[MAXN]; int next[MAXN]; void原创 2013-09-03 18:54:02 · 649 阅读 · 0 评论 -
hdu1358 Period (循环节)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358题解:当且仅当len%(len-next[len])==0时,str[next[len]~len-1]为最小循环节。字符编号从0开始,那么if(i%(i-next[i])==0),则i前面的串为一个轮回串,其中轮回子串出现i/(i-next[i])次。#include #incl原创 2013-09-03 17:46:34 · 642 阅读 · 2 评论 -
KMP算法
KMP字符串模式匹配详解来自优快云 A_B_C_ABC 网友KMP字符串模式匹配通俗点说就是一种在一个字符串中定位另一个串的高效算法。简单匹配算法的时间复杂度为O(m*n);KMP匹配算法。可以证明它的时间复杂度为O(m+n).。一. 简单匹配算法先来看一个简单匹配算法的函数:int Index_BF ( char S [ ], char T [ ], int po转载 2013-08-20 08:03:38 · 656 阅读 · 0 评论 -
hdu2087 剪花布条
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2087#include #include #define MAXN 1002 int next[MAXN],len1,len2; char text[MAXN],pattern[MAXN]; void原创 2013-08-20 20:43:41 · 512 阅读 · 0 评论 -
hdu2203 亲和串
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2203题解:要求一个串循环后是否包含另外一个串,只要将母串重复一次再进行KMP匹配,因为在重复母串的过程中,其实据已经将循环后的所有可能都列举出来了,比如串 "ABCD" 重复后为 "ABCDABCD" 在这个串中 "BCDA" , "CDAB" 以及 "DABC" 都接踵呈现了。原创 2013-08-20 20:21:43 · 645 阅读 · 0 评论 -
hdu1841 Find the Shortest Common Superstring
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1841题解:1.s1是s2的子串,或者s2是s1的子串。2.s1是s2的前缀或者后缀。#include #include #define MAXN 1000002 int next[MAXN]; char str1[MAXN],str2原创 2013-08-20 12:42:58 · 791 阅读 · 0 评论 -
hdu1686 Oulipo
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1686裸KMP#include #include #define MAXN 1000002 int next[10002],n,m; char text[MAXN],pattern[10002]; void getNext()原创 2013-08-20 08:24:01 · 733 阅读 · 0 评论 -
hdu2594 Simpsons’ Hidden Talents
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2594题解:finds the longest prefix of s1 that is a suffix of s2. s1作为模式串 s2作为原串,进行KMP #include #include #define MAXN 50002原创 2013-08-20 13:26:34 · 567 阅读 · 0 评论 -
hdu1711 Number Sequence
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1711题解:KMP模版题使用"输入外挂"时间缩短很多(484ms-->156ms) "输入外挂":http://blog.youkuaiyun.com/niushuai666/article/details/6689043#include #include #defi原创 2013-08-20 00:10:02 · 597 阅读 · 0 评论 -
Power Strings
DescriptionGiven two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponenti原创 2015-04-12 13:46:17 · 698 阅读 · 0 评论