Test instructions: Find the longest palindrome string, template problem
1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cmath>6#include <queue>7#include <map>8 using namespacestd;9 #defineMOD 1000000007Ten Const intinf=0x3f3f3f3f; One Const Doubleeps=1e-5; A #defineCL (a) memset (A,0,sizeof (a)) - #defineTS printf ("*****\n"); - intN,m,tt;Const intmaxn=110010; the Charma[maxn*2]; - intmp[maxn*2]; - voidManacher (CharS[],intlen) - { + intL=0; -ma[l++]='$'; +ma[l++]='#'; A for(intI=0; i<len;i++) at { -ma[l++]=S[i]; -ma[l++]='#'; - } -ma[l]=0; - intmx=0, id=0; in for(intI=0; i<l;i++) - { toMp[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) the { *mx=i+Mp[i]; $Id=i;Panax Notoginseng } - } the } + CharS[MAXN]; A intMain () the { + #ifndef Online_judge -Freopen ("1.in","R", stdin); $ #endif $ while(SCANF ("%s", s) = =1) - { - intlen=strlen (s); the Manacher (S,len); - intans=0;Wuyi for(intI=0;i<2*len+2; i++) theAns=max (ans,mp[i]-1); -printf"%d\n", ans); Wu } - return 0; About}
HDU 3068 Manacher algorithm