Bestcoders 回文串 Manacher 算法
来源:互联网 发布:淘宝直播怎么搜主播 编辑:程序博客网 时间:2024/06/03 04:05
Three Palindromes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 871 Accepted Submission(s): 262
Problem Description
Can we divided a given string S into three nonempty palindromes?
Input
First line contains a single integer T≤20 which denotes the number of test cases.
For each test case , there is an single line contains a string S which only consist of lowercase English letters.1≤|s|≤20000
For each test case , there is an single line contains a string S which only consist of lowercase English letters.
Output
For each case, output the "Yes" or "No" in a single line.
Sample Input
2abcabaadada
Sample Output
YesNo
Source
BestCoder Round #49 ($)
Recommend
hujie | We have carefully selected several similar problems for you: 5342 5341 5339 5338 5337
#include <bits/stdc++.h>using namespace std;int t;int p[220100];char s[220100], c[221000];int len;void palindrome(){ len = strlen(s); c[0] = '$'; for (int i = 0; i<len; i++) c[i * 2 + 1] = '#', c[i * 2 + 2] = s[i]; c[len * 2 + 1] = '#'; len = len * 2 + 2; c[len] = '\0'; int mx = 0, id = 0; for (int i = 1; i<len; i++) { if (mx>i) p[i] = min(p[id * 2 - i], mx - i); else p[i] = 1; while (c[i + p[i]] == c[i - p[i]]) p[i]++; if (i + p[i]>mx) mx = i + p[i], id = i; }}int solve(){ for(int i=2; i<len; i++) { if(i - p[i] != 0) continue; for(int j=i+p[i]; j<len; j++) { if(j-p[j]+1 <= i+p[i]) { int x = j - ( i + p[i] ); int last = (len + j + x) >> 1; if(last <= len - 2 && last + p[last] == len) return 1; } } } return 0;}int main(){ scanf("%d", &t); while (t--) { scanf("%s", s); palindrome(); if (solve()) printf("Yes\n"); else printf("No\n"); } return 0;}
0 0
- Bestcoders 回文串 Manacher 算法
- 【Manacher 算法 回文串】
- 回文串---manacher算法
- manacher回文串算法
- hdu3068回文串Manacher算法
- TJU1191-manacher回文串算法
- 回文串之manacher算法
- Manacher算法(最长回文串)
- (回文串)Manacher算法
- 回文串O(n)算法 Manacher算法
- Manacher 算法-----o(n)回文串算法
- Manacher算法(回文串匹配算法)
- Manacher算法求最长回文子串
- Manacher算法求最长回文子串
- HDU 4513 回文串Manacher算法
- 最长回文子串(Manacher算法)
- Manacher算法 最长回文子串
- Manacher算法求最长回文串
- 如何使用思维导图
- 第三方视频聊天解决----云通讯
- HDU 1796 容斥原理
- Android点击图片切换(用XML)
- 会计科目与账户
- Bestcoders 回文串 Manacher 算法
- poj 1655 Balancing Act 【树形DP 求树的重心】
- js闭包初体验
- 栈
- 南邮 OJ 1002 求最值
- 算法速成(1)七大排序算法
- 图解正向代理、反向代理、透明代理
- C语言文件操作函数大全(超详细)
- 二叉树遍历之(中序+先序,中序+后序)