1, find a longest palindrome substring, require the middle of the value of the largest, and then to the sides of the decrement.
2. The judging condition should be changed to: ma[i+mp[i]]==ma[i-mp[i]]&&ma[i-mp[i]]<=ma[i-mp[i]+2]
3.
#include <iostream>#include<stdio.h>#include<string.h>using namespacestd;//find the longest palindrome stringConst intmaxn=100005;intma[maxn*2];intmp[maxn*2];voidManacher (intS[],intLen) { intL=0; Ma[l++]=-1;//flag ' $ 'ma[l++]=255;//sign ' # ' for(intI=0; i<len;i++) {ma[l++]=S[i]; Ma[l++]=255; } Ma[l]=1;//sign ' + ' intmx=0, id=0; for(intI=0; i<l;i++) {Mp[i]=mx>i?min (mp[2*id-i],mx-i):1; while(ma[i+mp[i]]==ma[i-mp[i]]&&ma[i-mp[i]]<=ma[i-mp[i]+2]) mp[i]++; if(i+mp[i]>MX) {MX=i+Mp[i]; ID=i; } }}/*abaabai:0 1 2 3 4 5 6 7 8 9 Ten 13ma[i]:$ # a # b # a # a # b # a #Mp [i]:1 1 2 1 4 1 2 7 2 1 4 1 2 1*/intS[MAXN];intMain () {intT,n,i; scanf ("%d",&u); while(t--) {scanf ("%d",&N); for(i=0; i<n;++i) scanf ("%d",&S[i]); Manacher (S,n); intans=0; for(i=0;i<2*n+2;++i) ans=max (ans,mp[i]-1); printf ("%d\n", ans); } return 0;}
HDU-4513 Series Stories-Perfect Formations II (manacher)