Three Palindromes

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1680    Accepted Submission(s):
596

http://acm.hdu.edu.cn/showproblem.php?pid=5340

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

 

Output

For each case, output the "Yes" or "No" in a single
line.
 

Sample Input

2
abc
abaadada
 

Sample Output

Yes
No

题目大意:

【题目描述】
判断是否能将字符串S分成三段非空回文串。
【输入说明】
第一行一个整数T,表示数据组数。
对于每一个组,仅包含一个由小写字母组成的串。
【输出说明】
对于每一组,单行输出"Yes" 或 "No“
 
 
对每组数据跑一边Manacher是为了求最大半径数组rad[]
由于题目要求分成三部分,所以需要两个断点,分成第一、二、三三个部分
预处理出一、三为回文串的情况,也就是记录下回文前缀和回文后缀的位置,方便直接调用
枚举上一步找到的两个断点,确定下目前需要讨论的第二区间,其中点对应的半径*2-1如果>=区间长度,则说明符合条件,break掉
 
#include<iostream>//把注释去掉,上面的加注释将是另一种表示方法
#include<cstdio>
#include<cstring>
using namespace std;
int Case,rad[*],q1[*],q2[*];
char s[],c[*];
void manacher(){
int len=strlen(s+);
for(int i=len;i>=;i--){
c[i*]=s[i];
c[i*+]='#';
}c[]='$';
int k=;
for(int i=;i<=len*;i++){
if(rad[k]+k>i)rad[i]=min(k+rad[k]-i,rad[*k-i]);
else rad[i]=;
while(c[i-rad[i]]==c[i+rad[i]])rad[i]++;
if(i+rad[i]>k+rad[k])k=i;
}
}
int main(){
scanf("%d",&Case);
while(Case--){
int l=,r=;
memset(rad,,sizeof(rad));
memset(q1,,sizeof(q1));
memset(q2,,sizeof(q2));
scanf("%s",s+);
int n=strlen(s+);n=n*+;
manacher();
for(int i=;i<=n;i++){
if(i==rad[i]&&i!=)q1[++l]=i;
if(n+-i==rad[i]&&i!=n)q2[++r]=i;
/*if(i==rad[i]&&i!=1)q1[++l]=rad[i];
if(n+1-i==rad[i]&&i!=n)q2[++r]=rad[i];*/
}
bool flag=;int t1,t2;
for(int i=;i<=l;i++){
if(flag==)break;
for(int j=;j<=r;j++){
t1=q1[i]*;t2=n-*(n-q2[j])-;
/*t1=q1[i]*2;t2=n+1-q2[j]*2;*/
if(t1>t2)continue;
if(t2-t1==)continue;
int mid=(t1+t2)>>;
if(rad[mid]*->=t2-t1+){flag=;break;}
}
}
if(flag==){printf("Yes\n");}
else printf("No\n");
}
}

HDU5340 Three Palindromes的更多相关文章

  1. hdu5340—Three Palindromes—(Manacher算法)——回文子串

    Three Palindromes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  2. HDU-5340 Three Palindromes(字符串哈希)

    http://acm.hdu.edu.cn/showproblem.php?pid=5340 orz到了新的字符串hash姿势 #include<cstdio>#include<cs ...

  3. hdu5340 Three Palindromes(manacher算法)

    题目描写叙述: 推断能否将字符串S分成三段非空回文串. 解题思路: 源码: #include <cstdio> #include <algorithm> #define MAX ...

  4. UVA - 11584 Partitioning by Palindromes[序列DP]

    UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...

  5. hdu 1318 Palindromes

    Palindromes Time Limit:3000MS     Memory Limit:0KB     64bit                                         ...

  6. dp --- Codeforces 245H :Queries for Number of Palindromes

    Queries for Number of Palindromes Problem's Link:   http://codeforces.com/problemset/problem/245/H M ...

  7. Dual Palindromes

    Dual PalindromesMario Cruz (Colombia) & Hugo Rickeboer (Argentina) A number that reads the same ...

  8. ytu 1940:Palindromes _easy version(水题)

    Palindromes _easy version Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 47  Solved: 27[Submit][Statu ...

  9. 回文串+回溯法 URAL 1635 Mnemonics and Palindromes

    题目传送门 /* 题意:给出一个长为n的仅由小写英文字母组成的字符串,求它的回文串划分的元素的最小个数,并按顺序输出此划分方案 回文串+回溯:dp[i] 表示前i+1个字符(从0开始)最少需要划分的数 ...

随机推荐

  1. Java for LeetCode 126 Word Ladder II 【HARD】

    Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...

  2. java多线程---基础

    一, java多线程----线程与进程 进程: 程序(任务)的执行过程,拥有资源(共享内存,共享资源)和线程(一个或者多个,至少一个).  例如:打开任务管理器,qq,chrome,都属于进程. 线程 ...

  3. Java多线程系列 基础篇10 wait/notify/sleep/yield/join

    1.Object类中的wait()/notify()/notifyAll() wait(): 让当前线程处于Waiting状态并释放掉持有的对象锁,直到其他线程调用此对象的线程notify()/not ...

  4. 《avascript 高级程序设计(第三版)》 ---第三章 基本概念2

    1.乘性操作符: 1)*法操作法: Infinity * 0 = NaN  Infinity * 非零 = Infinity 或 - Infinity   2)/法操作符: Infinity / In ...

  5. java: new Date().getTime() 与 System.currentTimeMillis() 与 System.nanoTime()

    java使用new Date()和System.currentTimeMillis()获取当前时间戳   在开发过程中,通常很多人都习惯使用new Date()来获取当前时间,使用起来也比较方便,同时 ...

  6. Uncaught TypeError: Illegal invocation解决

    jquery中报了这个错,仔细一看,有个使用ajax的地方,其中有个参数是从页面某个文本框获取的,本应该 $('#id').value ,被我写成了 $('id') .所以报错,目前已解决.

  7. Go丨语言对MySQL数据库的增、删、改、查操作

    1.建立数据库名为: go_test_db 2.建表名为:userinfo 字段: uid int username varchar language varchar created varchar ...

  8. 开机时遇到grub rescue无法进入系统的解决方法

    装双系统(win10和elementary os),elementary os是ubuntu的一个分支.在win10中合并了一块空白磁盘分区,再开机的时候出问题了. 遇到filesystem unkn ...

  9. C++中的宏和const

    在C语言中使用const来定义一个变量,可以通过变量类型的指针形式来进行修改,而C++中增强了这种表现形式,使得即使通过类型变量指针也不能对变量进行修改. 在C++中const和宏是有区别的. con ...

  10. BZOJ1798:[AHOI2009]维护序列

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://www.lydsy.com/JudgeOnline/prob ...