题目传送门

 /*
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. bzoj4553 [Tjoi2016&Heoi2016]序列 树状数组(区间最大值)+cqd

    [Tjoi2016&Heoi2016]序列 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1006  Solved: 464[Submit][ ...

  2. android listVIew实现button按钮监听程序

    1.重写simpleAdapter 方法@Override public HashMap<String,String> getItem(int position) { // TODO Au ...

  3. SQL SERVER 自增字段相关问题

    SET IDENTITY_INSERT Data0048_TEST ON --给自增列赋值 DBCC CHECKIDENT(TableName) --查看某个表中的自增列当前的值 DBCC CHECK ...

  4. zoj2853 Evolution

    给定一个进化的矩阵图,问在m次之后最终的物种有多少个,实际上这和线性代数及其应用里的一个例题是一样的...总之就相当于煞笔的套个矩阵不断去乘m次,然后每次都会根据得到进化后各物种的个数,矩阵快速幂求一 ...

  5. golang中关闭http server

    golange 开启http server 服务之后,怎么关闭呢? ------------------------------------------------------------------ ...

  6. 在GNS3中模拟交换机和PC

    一.目标:使用ios c3640交换模块,模拟交换机 二.使用VPCS模拟PC机 VPCS模拟PC机软件下载:   http://down.51cto.com/data/195524 步骤1.启动GN ...

  7. 带头尾和动画的下拉刷新RecyclerView

    项目地址:https://github.com/shichaohui/AnimRefreshRecyclerView 项目中包括一个demo(普通Androidproject)和Android Lib ...

  8. 使用fiddler将网站上的css js重定向至本地文件

    使用fiddler将网站上的css js重定向至本地文件,进行在线调试 https://github.com/annnhan/ReRes 1条回复 这是一篇写给公司负责切图和调样式的前端的文章.主要适 ...

  9. Codeforces Round #324 (Div. 2)D. Dima and Lisa 数学(素数)

                                                     D. Dima and Lisa Dima loves representing an odd num ...

  10. 【codeforces379F】 New Year Tree

    距离一个点最远的点一定是直径的一个端点.考虑运用这个原理,每次维护一下直径端点即可. #include<algorithm> #include<iostream> #inclu ...