HDU 3068 求最大回文串
算法详解:
http://blog.csdn.net/xingyeyongheng/article/details/9310555
感谢大神
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main(void){
char str[110005];
char temp[300005];
int p[300005];
while(~scanf("%s",str)){
memset(p,0,sizeof(p));
int len = strlen(str);
temp[0]='*';
int i,j,k;
for(i=0;i<len;i++){
temp[i+i+1]='#';
temp[i+i+2]=str[i];
}
temp[i+i+1]='#';
int id = 0;
int maxlen = 0;
for(i=2;i<len*2+1;i++){
if(i<p[id]+id)p[i]=min(p[id]+id-i,p[2*id-i]);
else p[i]=1;
while(temp[i+p[i]] == temp[i-p[i]])p[i]++;
if(id+p[id]<i+p[i])id=i;
maxlen = max(maxlen,p[i]);
}
printf("%d\n",maxlen-1);
}
return 0;
}
继续加油~~~