标签:== number cto nts ack str mina mod sample
Input
Output
Sample Input
abcbabcbabcba abacacbaaaab END
Sample Output
Case 1: 13 Case 2: 6
manacher模板没啥好说的。(有一点要注意就是数组要开两倍大,不然就会runtime error)
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define pi acos(-1) #define ll long long #define mod 10007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-9; const int N=2000000+5,maxn=(1<<18)-1,inf=0x3f3f3f3f; string str; int p[N],slen; void manacher() { int mx=0,id; for(int i=1;i<slen;i++) { if(mx>i)p[i]=min(p[2*id-i],mx-i); else p[i]=1; while(str[i+p[i]]==str[i-p[i]])p[i]++; if(p[i]+i>mx) { mx=p[i]+i; id=i; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); // cout<<setiosflags(ios::fixed)<<setprecision(2); string s; int cnt=0; while(cin>>s){ if(s=="END")break; str="$#"; for(int i=0;i<s.size();i++) { str+=s[i]; str+="#"; } slen=str.size(); memset(p,0,sizeof p); manacher(); int ans=-1; for(int i=1;i<str.size();i++) ans=max(ans,p[i]-1); cout<<"Case "<<++cnt<<": "<<ans<<endl; } return 0; }
标签:== number cto nts ack str mina mod sample
原文地址:http://www.cnblogs.com/acjiumeng/p/6835398.html