hdu-3068(最长回文子串-manacher)
题意:求一个字符串
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char s[200005],a[200005];
int p[200005];
int n;
int change()
{
int i,j,t;
a[0]='$';
a[1]='#';
j=2;
for(i=0;i<n;i++)
{
a[j++]=s[i];
a[j++]='#';
}
a[j]='\0';
return j;
}
int manacher()
{
int len=change();
int maxlen=-1;
int id;
int mx=0;
for(int i=1;i<len;i++)
{
if(i<mx)
p[i]=min(p[id*2-i],mx-i);
else
p[i]=1;
while(a[i-p[i]]==a[i+p[i]])
p[i]++;
if(mx<p[i]+i)
{
mx=p[i]+i;
id=i;
}
maxlen=max(maxlen,p[i]-1);
}
return maxlen;
}
int main()
{
while(cin>>s)
{
n=strlen(s);
cout<<manacher()<<endl;
}
}