KMP 、扩展KMP、Manacher算法 总结

一. KMP

1 找字符串x是否存在于y串中,或者存在了几次

HDU1711 Number Sequence 

HDU1686 Oulipo 

HDU2087 剪花布条 

2.求多个字符串的最长公共子串

POJ3080 Blue Jeans

HDU1238 Substrings 

3.next数组的应用

1) 求循环节

HDU3746 Cyclic Nacklace

HDU1358 Period

POJ2406 Power Strings

HDU3374 String Problem

2) 利用next数组的回退来求值:

HDU3336 Count the string

HDU4300 Clairewd’s message 

FZU1901 Period II 

HDU4763 Theme Section

4.即是前缀又是后缀

POJ2752 Seek the Name, Seek the Fame

HDU2594 Simpsons’ Hidden Talents

HDU4763 Theme Section

二.扩展KMP

1)求前缀、后缀是否为回文串

HDU3613 Best Reward

POJ3376 Finding Palindromes

三.Manacher算法

1)单纯的求最长回文串长度

51Nod 1089 最长回文子串 V2 

HDU4513 吉哥系列故事

2)求出最长回文串的位置

HDU3294 Girls' research

HDU3613 Best Reward 

四.最小最大表示法:

模板:

int getmin(char *s, int len, int type)  //当type为1时,为最小表示法;当type为-1时,为最大表示法
{
    int i = 0, j = 1, k = 0;
    while(i<len && j<len && k<len)
    {
        int t = s[(i+k)%len]-s[(j+k)%len];
        if (!t) k++;
        else
        {
            //当t>0时,i~i+k的位置都不可能作为起始点,因为在j~j+k处有更优值。同理j。
            if (type*t>0) i += k+1;     //唯一不同的地方
            else j += k+1;
            if (i==j) j++;
            k = 0;
        }
    }
    return i<j?i:j;
    /*
    为什么要返回下标小的呢?
    看循环条件,可知:当i、j、k其中一个等于len时,循环结束。
    1) 当k==len时,表明在i处的表示等于在j处的表示。那么随便哪一个都行
    2) 当k!=len时,即i或j其中一个等于len,那么等于len的那个下标其实已经溢出了。所以取小的那个
    综上:return min(i, j);
    */
}
View Code

HDU2609 How many 

51Nod 1282 时钟

HDU3374 String Problem

原文地址:https://www.cnblogs.com/DOLFAMINGO/p/7899197.html