标签:scanf hint return man ada stream max manacher div
abcdcba
abacada
abcdef
0
2
5
#include<iostream> #include<cstdio> #include<cstring> #include<cctype> using namespace std; template <typename T> inline T min(T &a,T &b) {return a<b ?a:b;} template <typename T> inline T max(T &a,T &b) {return a>b ?a:b;} char a[1000005],b[1000005]; int p[1000005],f[1000005]; int main(){ while(scanf("%s",a)!=EOF){ memset(f,0,sizeof(f)); int len=strlen(a),n=0,id=0,mx=-1,last,mxd,ans=0; for(int i=0;i<len;++i) b[n++]=‘#‘,b[n++]=a[i]; b[n++]=‘#‘; for(int i=0;i<n;++i){ if(i<mx) p[i]=min(p[id*2-i],mx-i+1); else p[i]=1; while(i-p[i]>=0&&i+p[i]<n&&b[i-p[i]]==b[i+p[i]]) ++p[i]; if(i+p[i]-1>mx) mx=i+p[i]-1,id=i; f[i-p[i]+1]=i+p[i]-1; //处理出从点i-p[i]+1开始的最长回文串长度 }last=mxd=f[0]+2; for(int i=0;i<n;i+=2){ //贪心 if(i==last) last=mxd,++ans; mxd=max(mxd,f[i]+2); }printf("%d\n",ans); }return 0; }
标签:scanf hint return man ada stream max manacher div
原文地址:https://www.cnblogs.com/kafuuchino/p/9710442.html