很好的总结,转自: http://blog.csdn.net/dyx404514/article/details/42061017 总结为:两大情况,三小情况. 两大情况:I. i <= p 1.要处理的位置i及i为中心的回文半径Len[i] < p-i已经完全包含在某个回文中了,这种情况不用计算,len[i] = len[j]. 2.要处理的位置i在某个回文中,但是以i为中心的回文半径len[i] >= p-i,需要往后匹配,重新更新p,及对应的po和Len[i]; II. i >…
引 入 引入 引入 Manachar算法主要是处理字符串中关于回文串的问题的,这没什么好说的. M a n a c h e r 算 法 Manacher算法 Manacher算法 朴素 求一个字符串中以每个点为中心的最长回文子串,这是 m a n a c h e r manacher manacher 直接解决的问题. 以每个点为中心的回文子串是连续的,它并不像字符串的 b o r d e r border border ,因此可以二分,于是在不知道 m a n a c h e r manach…
题目连接:hdu 3068 最长回文 解题思路:通过manachar算法求最长回文子串,如果用遍历的话绝对超时. #include <stdio.h> #include <string.h> const int N = 220005; int rad[N]; char string[N], tmpstr[N]; int max(int a, int b) { return a > b ? a : b; } int min(int a, int b) { return a &l…