Sample Input
2
abc
abaadada
 
Sample Output
Yes
No

判断是否能成为3个非空回文子串

manacher算法求出个点回文长度,在找出第一个和最后一个保存下来,再判断中间的

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 3221225473
#define MAXN 20005
#define MIN 0
#define MAX 1000001 int n;
char d[MAXN];
char st[MAXN*2];
int p[MAXN*2],begi[MAXN*2],tail[MAXN*2];
int len;
void manacher()
{
int MaxId=0,id;
for(int i=0; i<len; i++)
{
if(MaxId>i)
p[i]=min(p[2*id-i],MaxId-i);
else
p[i]=1;
while(st[i+p[i]]==st[i-p[i]])
p[i]++; if(p[i]+i>MaxId)
{
id=i;
MaxId=p[i]+i;
}
p[i] -= 1;
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
getchar();
scanf("%s",d);
int l = strlen(d); len = 0;
st[len++] = '#';
for(int i = 0; i < l; i++)
{
st[len++] = d[i];
st[len++] = '#';
}
st[len] = 0;
manacher(); int flag = 0;
int pn =0 ,ln = 0;
for(int i = 1; i < len - 1; i++)
{
if(i - p[i] == 0) begi[pn++] = i;
if(i + p[i] == len-1) tail[ln++] = i;
}
for(int i = 0; i < pn; i++)
{
for(int j = ln - 1; j>=0; j--)
{
int s1 = begi[i] + p[begi[i]]+1 ,s2 = tail[j] - p[tail[j]]-1;
if(s1 > s2)
break;
int mid = (s1 + s2)/2;
if(p[mid] >= mid-s1)
{
flag = 1;
break;
}
}
if(flag )
break;
}
if(flag )
printf("Yes\n");
else
printf("No\n");
}
return 0;
}

  

hdu 5340 (manacher)的更多相关文章

  1. hdu 4513(Manacher)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4513 题解:就是在Manacher判断回文串的过程中添加一条条件 Ma[i + dp[i] - 2] ...

  2. 吉哥系列故事--完美队形 - HDU 4513 (Manacher)

    分析:刚开始的想法是匹配出来每个点的最大回文串,然后用每个点的最大不下降序找一个最小值,不过不明白为什么不对....很无奈,再匹配的时候加一些判断就可以过,或许还有什么没想到的地方吧.....   代 ...

  3. O(n)回文子串(Manacher)算法

    O(n)回文子串(Manacher)算法 资料来源网络 参见:http://www.felix021.com/blog/read.php?2040 问题描述: 输入一个字符串,求出其中最大的回文子串. ...

  4. A * B Problem Plus HDU - 1402 (FFT)

    A * B Problem Plus HDU - 1402 (FFT) Calculate A * B.  InputEach line will contain two integers A and ...

  5. 【学习笔记】字符串—马拉车(Manacher)

    [学习笔记]字符串-马拉车(Manacher) 一:[前言] 马拉车用于求解连续回文子串问题,效率极高. 其核心思想与 \(kmp\) 类似:继承. --引自 \(yyx\) 学姐 二:[算法原理] ...

  6. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  7. HDU 4513 吉哥系列故事——完美队形II(Manacher)

    Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成 ...

  8. 牛客小白月赛13 小A的回文串(Manacher)

    链接:https://ac.nowcoder.com/acm/contest/549/B来源:牛客网 题目描述 小A非常喜欢回文串,当然我们都知道回文串这种情况是非常特殊的.所以小A只想知道给定的一个 ...

  9. hdu 5055(坑)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5055 Bob and math problem Time Limit: 2000/1000 MS ( ...

随机推荐

  1. CPP链表示例

    #include<iostream> #include<stdlib.h> using namespace std; typedef struct Student_data { ...

  2. python 异步协程

    """A very simple co-routine scheduler. Note: this is written to favour simple code ov ...

  3. 【iOS】跳转到设置页面

    iOS8.0以后有效 定位服务 定位服务有很多APP都有,如果用户关闭了定位,那么,我们在APP里面可以提示用户打开定位服务.点击到设置界面设置,直接跳到定位服务设置界面.代码如下: 1 2 3 4 ...

  4. (原创)不带模板的OLE输出EXCEL

    目前我已知的EXCEL输出方式有3种: 1.GUI_DOWNLOAD函数输出(适用于简单无格式要求的输出). 2.OLE输出(适用于对EXCEL格式输出有特殊要求的,但是因其填充数据和设置格式是基于一 ...

  5. JAVA_SE基础——62.String类的构造方法

    下面我先列出初学者目前用到的构造方法 String 的构造方法:     String()  创建一个空内容 的字符串对象.   String(byte[] bytes)  使用一个字节数组构建一个字 ...

  6. STM32常见问题

    一.STM32 下不了程序 提示: (1).JLink Info: CPU halted Erase Done. Programming Failed! 解决办法: 用isp把芯片全部擦除再试试,如果 ...

  7. 扩展Microsoft Graph数据结构 - 架构扩展

    前言 此前我有一篇 文章 讲解了Microsoft Graph的一种数据扩展技术-- 开发扩展(Open Extensions),它可以实现在支持的对象(例如用户,组等)上面附加任意的数据.但开放扩展 ...

  8. c#+wpf项目性能优化之OutOfMemoryException解密

    近期,使用c#+wpf开发的软件准备正式投入使用了,使用前进行了大量的测试,测试后发现了一些问题,其中最让人头疼的就是软件的性能问题(稳定性). 这里的稳定性具体表现在机器的cpu占有率和内存使用情况 ...

  9. Python内置函数(51)——hasattr

    英文文档: hasattr(object, name) The arguments are an object and a string. The result is True if the stri ...

  10. css(1-1)样式表

    CSS Id 和 Class id 和 class 选择器 如果你要在HTML元素中设置CSS样式,你需要在元素中设置"id" 和 "class"选择器. id ...