Title Link: http://poj.org/problem?id=3974
Test instructions: To find the length of the longest palindrome substring of a given string
Idea: Direct set template Manacher algorithm
Code
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Const intMAXN =1000010;6 Charma[2*MAXN];7 intmp[2*MAXN];8 9 voidManacher (CharS[],intlen)Ten { One intL =0; Ama[l++] ='S'; -ma[l++] ='#'; - for(inti =0; i < Len; ++i) the { -ma[l++] =S[i]; -ma[l++] ='#'; - } +MA[L] =0; - intMX =0; + intID =0; A for(inti =0; I < L; ++i) at { -Mp[i] = mx > I? Min (mp[2*id-i], Mx-i):1; - while(Ma[i+mp[i] [= Ma[i-mp[i]]) + +Mp[i]; - if(i + mp[i] >mx) - { -MX = i +Mp[i]; inID =i; - } to } + } - the CharS[MAXN]; * $ intMain ()Panax Notoginseng { - intCNT =0; the while(SCANF ("%s", s)! =EOF) + { A if(strcmp (s),"END") ==0) Break; the intLen =strlen (s); + Manacher (S, Len); - intAns =0; $Len =2* Len +2; $ for(inti =0; i < Len; ++i) ans = max (ans, mp[i)-1); -printf"Case %d:%d\n",++cnt, ans); - } the return 0; -}
POJ 3974 palindrome