标签:++ man 超过 space ane UI algorithm panel ems
#include<iostream> #include<stdio.h> #include<stdlib.h> #include<algorithm> #include<cstring> using namespace std; char x[110010]; char xx[1100010]; int k=0,len[1100010],ans; void cl(){ memset(len,0,sizeof(len)); k=0; ans=0; } void build(char x[]){ int len1=strlen(x); xx[0]=‘$‘; for(int i=0;i<len1;i++) xx[++k]=‘#‘,xx[++k]=x[i]; xx[++k]=‘#‘; } void manacher(){ int ans=0,id,ma=0; for(int i=1;i<=k;i++){ if(ma>i) len[i]=min(ma-i,len[id*2-i]); else len[i]=1; while(xx[i+len[i]]==xx[i-len[i]]) len[i]++; if(ma<i+len[i]) id=i,ma=len[i]+i; } } int main(){ while(scanf("%s",&x)!=EOF){ cl(); build(x); manacher(); for(int i=1;i<=k;i++) ans=max(ans,len[i]-1); printf("%d\n",ans); } }
标签:++ man 超过 space ane UI algorithm panel ems
原文地址:http://www.cnblogs.com/renjianshige/p/7173350.html