标签:
2 abc abaadada
Yes No
#define N 110050 #define M 100005 #define maxn 205 #define MOD 1000000000000000007 int T,n,a,pri[N],ans,len,sn = 0,top[N],tail[N],pn,ln; bool dp[N][4]; pii seg[N]; bool Manacher(char str[],int len){ char tstr[N+N]; int p[N + N],l2 =0,mi; tstr[l2++] = '#'; for(int i =0;i<len;i++){ tstr[l2++] = str[i]; tstr[l2++] = '#'; } p[0] = 0;mi = 0; for(int i = 1;i<l2;i++){ int mi2 = mi + mi - i; if(mi + p[mi] >= i) p[i] = min(mi2 - (mi - p[mi]),p[mi2]); else p[i] = 0; if(p[i] == 0 || mi2 - p[mi2] == mi - p[mi]){ int maxx = p[i]+1; while(i- maxx >= 0 && i+maxx < l2 && tstr[i-maxx] == tstr[i+maxx]){ maxx++; } p[i] = maxx - 1; } if(p[i] + i > p[mi] + mi) mi = i; } int ans = -1;sn = 0;pn = ln = 0; for(int i = 1;i < l2 - 1;i++){ if(i - p[i] == 0) top[pn++] = i; if(i + p[i] == l2 - 1) tail[ln++] = i; } for(int i = 0;i < pn;i++){ for(int j = ln - 1;j>=0;j--){ int s1 = top[i] + p[top[i]] + 1,s2 = tail[j] - p[tail[j]] - 1; if(s1 > s2 ) break; int mid = (s1 + s2)/2; if(p[mid] >= mid - s1) return true; } } return false; //printf("%d\n",ans); } char str[N]; int main() { while(S(T)!=EOF) { while(T--){ SS(str); len = strlen(str); if(Manacher(str,len)) printf("Yes\n"); else printf("No\n"); } } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
Hdu 5340 Three Palindromes 最大回文串 Manacher
标签:
原文地址:http://blog.csdn.net/mengzhengnan/article/details/47190779