HDU5340-Three Palindromes
来源:互联网 发布:爱福窝软件多少钱一年 编辑:程序博客网 时间:2024/06/05 05:32
Three Palindromes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1728 Accepted Submission(s): 611
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
解题思路:用Manachar计算以每个字符为中心的最长回文串长度,然后枚举头尾的回文串,判断中心是否为回文串
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <cmath>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;char s1[20009], s2[40009];int p[40009];int a[40009], b[40009];int main(){int t;scanf("%d", &t);while (t--){scanf("%s", s1);s2[0] = '$';int len = 1, i = 0;while (s1[i]){s2[len++] = '#';s2[len++] = s1[i++];}s2[len++] = '#';s2[len] = '\0';memset(p, 0, sizeof p);int id = 0, ma = 0;for (int i = 0; i < len; i++){p[i] = ma > i ? min(p[id * 2 - i], ma - i) : 1;while (s2[i + p[i]] == s2[i - p[i]]) p[i]++;if (i + p[i] > ma){ma = i + p[i];id = i;}}int cnt1 = 0, cnt2 = 0;for (int i = 2; i < len - 1; i++){if (p[i] == i) a[cnt1++] = i;if (p[i] == len - i) b[cnt2++] = i;}int flag = 0;for (int i = 0; i < cnt1; i++){for (int j = 0; j < cnt2; j++){int l = a[i] + p[a[i]];int r = b[j] - p[b[j]];int mid = (l + r) >> 1;if (l > r || (l == r&&s2[mid] == '#')) continue;if (p[a[i]] * 2 - 1 + p[mid] * 2 - 1 + p[b[j]] * 2 - 1 >= len - 1) {flag = 1; break;}}if (flag) break;}if (flag) printf("Yes\n");else printf("No\n");}return 0;}
阅读全文
0 0
- HDU5340.Three Palindromes
- HDU5340 Three Palindromes
- HDU5340-Three Palindromes
- HDU5340 Three Palindromes <Manacher>
- hdu5340 Three Palindromes(manacher算法)
- hdu5340--Three Palindromes(Mannacer算法)
- BestCoder Round #49 Three Palindromes 即 hdu5340 (manacher算法)
- BestCoder Round #49 HDU5340 Three Palindromes Manacher算法
- Three Palindromes
- HDOJ 5340 Three Palindromes
- hdu 5340 Three Palindromes
- hdu 5340 Three Palindromes
- hdu 5340 Three Palindromes
- HDOJ 5430 Three Palindromes
- hdu 5340 Three Palindromes 【Manacher】
- hdu 5340 Three Palindromes(manacher)
- HDU 5340 Three Palindromes(Manacher乱搞)
- [HDU 5340] Three Palindromes 最长回文串
- Unity多线程(Thread)和主线程(MainThread)交互使用类——Loom工具分享
- 多态参数和环境造型
- wamp黄(橙)色图标解决方法
- window下的免安装redis
- Linux最基础
- HDU5340-Three Palindromes
- 成功解决mysql中新建用户无法登陆报1044错误方案-副作用未知
- 第二章
- JavaScript基础笔记_17-07-12
- CodeFroces Round 423 A. Restaurant Tables
- FFMPEG中的两输入Filter实现(一)
- 面试题35:第一个只出现一次的字符
- 用c语言做的简易的动态显示直方图和一个有趣的反直觉财富分配实验
- iOS 中的类属性