题意:
给一个字符x代表真实的a 然后输出的时候转换
然后就是求最长回文子串的串是什么 长度要大于1
思路:
就是裸的manacher,弄清楚下标的转换关系就好了
代码:
#include"cstdlib" #include"cstdio" #include"cstring" #include"cmath" #include"queue" #include"algorithm" #include"map" #include"vector" #include"string" #define inf 0x7fffffff #include"iostream" #define ll __int64 using namespace std; #define N 200005 char a[N],b[N*2]; int rad[N*2]; int main() { char x[2]; while(scanf("%s%s",x,&a[1])!=-1) { int maxl,maxid,id; int i,len; for(i=1; a[i]; i++) { b[i*2]=a[i]; b[i*2+1]='#'; } len=2*i; b[0]='?'; b[1]='#'; b[len]='\0'; maxid=id=0; maxl=0; int ansi; for(i=1; i<len; i++) { if(maxid>i) rad[i]=min(rad[2*id-i],maxid-i); else rad[i]=1; while(b[i-rad[i]]==b[i+rad[i]]) { rad[i]++; } if(rad[i]+i>maxid) { maxid=rad[i]+i; id=i; } if(rad[i]>maxl) { maxl=rad[i]; ansi=i; } } if(maxl-1<2) puts("No solution!"); else { int kk=x[0]-'a'; int ans=maxl-1,ansl,ansr; ansl=(ansi-(ans-1))/2-1; ansr=ansl+ans-1; printf("%d %d\n",ansl,ansr); for(int i=ansl; i<=ansr; i++) { if(a[i+1]-kk<'a') printf("%c",'z'+1-'a'+(a[i+1]-kk)); else printf("%c",a[i+1]-kk); } puts(""); } } return 0; }
[manacher] hdu 3294 Girls' research
时间: 2024-09-30 18:06:30