题目传送门

 /*
Manacher:该算法能求最长回文串,思路时依据回文半径p数组找到第一个和第三个会文串,然后暴力枚举判断是否存在中间的回文串
另外,在原字符串没啥用时可以直接覆盖,省去一个数组空间,位运算 >>1 比 /2 速度快,用了程序跑快200ms左右,位运算大法好
*/
/************************************************
Author :Running_Time
Created Time :2015-8-1 20:10:22
File Name :B.cpp
*************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; typedef long long ll;
const int MAXN = 2e4 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
char s[MAXN*];
int p[MAXN*], fi[MAXN*], ei[MAXN*];
int len; void Manacher(void) {
for (int i=len; i>=; --i) {
s[i*+] = s[i]; s[i*+] = '#';
}
s[] = '$'; len = len * + ;
int id = ; p[] = ;
for (int i=; i<len; ++i) {
if (id + p[id] > i) p[i] = min (p[*id-i], id + p[id] - i);
else p[i] = ;
while (s[i-p[i]] == s[i+p[i]]) p[i]++;
if (id + p[id] < i + p[i]) id = i;
}
} bool judge(void) {
int c1 = , c2 = ;
for (int i=; i<len-; ++i) {
if (p[i] == i) fi[++c1] = i;
if (i + p[i] == len) ei[++c2] = i;
}
for (int i=; i<=c1; ++i) {
for (int j=; j<=c2; ++j) {
int l = fi[i] + p[fi[i]];
int r = ei[j] - p[ei[j]];
if (l > r) continue;
int mid = (l + r) >> ;
if (p[mid] > (r - l + ) >> ) return true;
}
}
return false;
} int main(void) { //BestCoder Round #49 ($) 1002 Three Palindromes
int T; scanf ("%d", &T);
while (T--) {
scanf ("%s", s);
len = strlen (s);
if (len < ) {
puts ("NO"); continue;
}
Manacher ();
judge () ? puts ("Yes") : puts ("No");
} return ;
}

Manacher BestCoder Round #49 ($) 1002 Three Palindromes的更多相关文章

  1. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  2. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢?可以用矩阵快速幂来加速计算.我们可以用矩阵来表示数列递推公式比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [f(n ...

  3. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...

  4. 二分图判定+点染色/并查集 BestCoder Round #48 ($) 1002 wyh2000 and pupil

    题目传送门 /* 二分图判定+点染色:因为有很多联通块,要对所有点二分图匹配,若不能,存在点是无法分配的,no 每一次二分图匹配时,将点多的集合加大最后第一个集合去 注意:n <= 1,no,两 ...

  5. BestCoder Round #49

    呵呵哒,1001的dfs返回值写错,wa了两发就没分了,1002显然是PAM可是我没学过啊!!!压位暴力可不可以...看看范围貌似不行,弃疗...1003根本不会做,1004想了想lcc发现不可做,那 ...

  6. hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

    传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131 ...

  7. BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle (dp,二维bit或线段树)

    今天第二次做BC,不习惯hdu的oj,CE过2次... 1002 Clarke and problem 和Codeforces Round #319 (Div. 2) B Modulo Sum思路差不 ...

  8. BestCoder Round #92 1002 Count the Sheep —— 枚举+技巧

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1002 题解: 做题的时候只是想到 ...

  9. BestCoder Round #80 1002

    HDU 5666 Segment 题意:给你条斜率为-1,常数项为q(q为质数)的直线,连接原点与直线上整数格点,问你在有多少个格点在形成的无数个三角形内,而不在线段上,结果对P取模. 思路:best ...

随机推荐

  1. 【Intellij】Intellij Idea 2017创建web项目及tomcat部署实战

    相关软件:Intellij Idea2017.jdk16.tomcat7 Intellij Idea直接安装(可根据需要选择自己设置的安装目录),jdk使用1.6/1.7/1.8都可以,主要是配置好系 ...

  2. POJ2586 Y2K Accounting Bug 解题报告

    Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vi ...

  3. docker: 通过docker方式安装jenkins

    1. docker pull jenkins 2. docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home:z -t jenkins ...

  4. AE After Effect 如何分段渲染

    如果只要第一段的话,你把要输出的那段首尾处分别按下B键和N键,这样输出时就会只输出这一段了(拖动首尾的栏目修改起始和终止的时间):如果是批量渲染的话你只要在这些不同的合成层里,每个按下ctrl+M键, ...

  5. 杭电 3555 Bomb

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Subm ...

  6. Cookies 初识 Dotnetspider EF 6.x、EF Core实现dynamic动态查询和EF Core注入多个上下文实例池你知道有什么问题? EntityFramework Core 运行dotnet ef命令迁移背后本质是什么?(EF Core迁移原理)

    Cookies   1.创建HttpCookies Cookie=new HttpCookies("CookieName");2.添加内容Cookie.Values.Add(&qu ...

  7. web 页面传值乱码问题

    今天碰到一个问题,将A页面中文值传到B页面,session保存,然后在C页面显示,页面显示乱码 百度了一下什么原因,以为是session保存中乱码,于是将B页面的通过Server.UrlDecode( ...

  8. linux文件系统的权限简单介绍

    linux系统下,文件的权限是这样表示的: - --- --- --- 一共用10位的二进制进行表示,其中 位置 0 :  - :文件        d :目录剩下的9个位置:位置1-3 当前用户(应 ...

  9. 使用mpxj读取MSPrjoect

    import java.util.ArrayList; import java.util.Calendar; import java.util.Hashtable; import java.util. ...

  10. Genymotion模拟器连接不上开发服务器解决办法

    问题截图: 问题原因:虚拟机没有联网.可以打开虚拟机的浏览器随便打开一个网站试一下能不能正常上网.如果不能正常上网. 第一步: 打开VirtualBox 点击确定.重启Genymotion.