
字符串
文章平均质量分 77
小小小小葱
这个作者很懒,什么都没留下…
展开
-
最小表示法 字符串循环同构问题
用最小表示法返回最小表示串(字典序最小的同构串)第一个字符在原始串中的下标。 用两个指针i,j,i初始化为0,j初始化为1,用k表示当前已经匹配串的长度。如果str[i+k]==str[j+k],j++,否则如果str[i+k]>str[j+k],说明以i开始的同构串肯定不是最小的,并且以i开始的到以i+k开始的都不会是最小的,因为若以i+x开头,0str[j+k],把j移到j+k+1,如果原创 2015-01-26 19:21:23 · 1467 阅读 · 1 评论 -
uva11888 - Abnormal 89's Manacher回文子串
Abnormal 89's A palindrome is a word that can be read the same way in either direction. More formally if a string isd (d > 0) characters length and thei-th character is ai, the string原创 2015-01-24 13:38:38 · 496 阅读 · 0 评论 -
uva11475 - Extend to Palindrome KMP
Your task is, given an integerN, to make a palidrome (word that reads the same when you reverseit) of length at leastN. Any palindrome will do. Easy, isn't it? That's what you though原创 2015-01-03 17:50:11 · 516 阅读 · 0 评论 -
KMP
KMP是个字符串匹配的算法。 如果想知道一个字符串在另一个字符串中出现没有或者出现几次,最暴力的方法是一个一个比较。假设有两个串ababcabcacbab和abcac,i和j分别表示第一个串和第二个串匹配到的位置,普通方法是i=0,j=0,a[i]=b[j], i++,j++,i=1,j=1,i++,j++,i=2,j=2,此时a[i]!=b[j],接下来i=1,j=0.再开始比较。。原创 2013-08-07 21:35:22 · 595 阅读 · 0 评论 -
uva12338 - Anti-Rhyme Pairs 询问最长公共前缀 HASH+二分
Often two words that rhyme alsoend in the same sequence of characters. We use this property to define theconcept of an anti-rhyme. An anti-rhyme is a pair of words that have a similar beginning.The de原创 2015-01-03 17:53:45 · 806 阅读 · 0 评论 -
hash
做了一点简单的hash,刚开始用set,总结一下。 hash表通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度。 比如这就是一种方法Let consist of positiveintegers .The problem is to find the smallest positiveintegerC such that for all .原创 2013-08-15 16:54:00 · 855 阅读 · 0 评论 -
Manacher算法 O(n)回文子串算法
首先把字符串的每个字符之间用和所有字符都不一样的分隔符隔开,并且在最前头加一个非0的分隔符,比如*。例如aba就变成*#a#b#a0,0是字符串的结束符。 这样处理之后得到的串所有回文串都是奇数长度。 用p[i]表示以下标为i的字符为中心的回文串的半边的长度,包括中心字符i,因为回文串长度都是奇数,设为2*n-1的话,p[i]就等于n。那么设i+p[i]是这个回文串能够向右扩展的位置(原创 2015-01-24 13:22:24 · 714 阅读 · 0 评论