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. Hibernate之Hibernate的体系结构

    体系结构简图: 这是一张体系结构的简图,其中的hibernate.properties文件的作用相当于配置文件hibernate.cfg.xml XML Mapping对应的就是映射文件 XXXX.h ...

  2. linux系统命令学习系列-用户组管理

    先复习一下上节内容: 设置密码命令passwd 用户信息修改命令usermod 用户删除命令userdel 作业:修改user1的用户id为505,家目录到admin,用户组为admin,最后删除us ...

  3. HTML 字符集

    在 HTML 中,正确的字符编码是什么?   HTML5 中默认的字符编码是 UTF-8. 这并非总是如此.早期网络的字符编码是 ASCII 码.后来,从 HTML 2.0 到 HTML 4.01,I ...

  4. JAVA_SE基础——65.StringBuffer类 ②

    字符串特点:字符串是常量:它们的值在创建之后不能更改.    字符串的内容一旦发生了变化,那么马上会创建一个新 的对象.    注意: 字符串的内容不适宜频繁修改,因为一旦修改马上就会创建一个新的对象 ...

  5. JAVA_SE基础——53.什么是异常?

    尽管人人都希望自己的身体健康,处理事情都能顺利进行, 但是在实际生活中总会遇到各种状况,比如,感冒发烧,电脑突然蓝屏死机等..程序也一样,程序在运行过程中,也会发生各种非正常状况,比如程序运行时磁盘不 ...

  6. 完美解决ubuntu Desktop 16.04 中文版firefox在非root用户不能正常启动的问题

    ubuntu安装好后,默认安装有firefox浏览器,不过,非root的账户登录,双击firefox图标,居然出现如下提示:Your Firefox profile cannot be loaded. ...

  7. django报错Manager isn't accessible via UserInfo instances

    出现这种错误是因为调用模型对象时使用了变量名,而不是对象名(模型类),例如: user = UserInfo()user_li = user.objects.filter(uname=username ...

  8. js前端对后台数据的获取,如果是汉字则需要添上引号

    js前端对后台数据的获取,如果是汉字则需要添上引号

  9. Python内置函数(45)——ascii

    英文文档: ascii(object) As repr(), return a string containing a printable representation of an object, b ...

  10. 译《Time, Clocks, and the Ordering of Events in a Distributed System》

    Motivation <Time, Clocks, and the Ordering of Events in a Distributed System>大概是在分布式领域被引用的最多的一 ...