
字符串匹配
-
原创
练习:KMP(字符串模式匹配问题)
KMP算法是模式串匹配算法中最为著名的一个,其他的还有BM、Horspool、Sunday等。 这篇文章,对各种算法有比较全面的介绍。但是,其中代码尚存在问题,不能照搬,重在理解各种算法思想。 KMP算法应用最多(至少在ACM竞赛中出现频率很高),因此需要深入理解,熟练掌握。其O(n+m)的时间复杂度,也是非常出色的。 在我看过的几篇材料中,这篇文章,对KMP算法的介绍比较透彻。可惜的是,有2016-02-03 22:49:26 阅读数 618 评论数 0 -
原创
poj_3450 Corporate Identity(KMP+枚举)
【题目】 点击这里 【思路】 同poj_3080 Blue Jeans,依然秒AC(1100ms 【代码】 #include #include char a[4002][201]; int next[202]; void getNext(char t[], int x, int y) { int i=x, j=x-1; next[i]=j; while (i<2016-02-06 18:04:50 阅读数 177 评论数 0 -
原创
poj_3080 Blue Jeans(KMP应用)
【题目】 点击这里 【思路】 按照长度从大到小的顺序,枚举第一个串的子串,每次都尝试将此子串与其他串匹配,直至所有匹配都成功。注意最后输出的是,长度尽可能大且字典序最小的子串。 原本以为时间上可能有压力,没想到KMP算法效率非常高,枚举+KMP结果秒AC,O(∩_∩)O哈哈~ 【代码】 #include #include char a[11][61]; int next[2016-02-06 15:32:50 阅读数 241 评论数 0 -
原创
poj_2752 Seek the Name, Seek the Fame(KMP:寻找所有公共前缀后缀)
【题目描述】 The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time2016-02-04 20:32:08 阅读数 263 评论数 0 -
原创
poj_2406 Power Strings(KMP求周期子串)
【题目描述】 Given 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, exponentiation b2016-02-04 18:36:23 阅读数 206 评论数 0 -
原创
poj_3461 Oulipo(KMP:找出所有模式串)
本题就是经典的模式串匹配问题,只需要对上文中的程序稍作修改即可。(hihoCoder上的KMP算法一题,与本题一模一样) #include #include void getNext(char t[], int next[]) { int i=0, j=-1, tLen=strlen(t); next[i]=j; while (i<tLen) if2016-02-04 11:52:28 阅读数 339 评论数 0