题目传送门

 /*
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. hiho一下 第四十九周 欧拉路

    http://hihocoder.com/contest/hiho49/problem/1 给定无孤立结点图G,若存在一条路,经过图中每边一次且仅一次,该条路称为欧拉路. 一个无向图存在欧拉路当且仅当 ...

  2. 组队训练1 回放(转载至cxhscst2's blog)

      第一场组队训练……意料之中的爆炸. 开场先看题,H是斐波那契水题,qw把H切了. 同时czy看I题(排列),cst继续读其他题. czy尝试交I,PE. cst发现K是水题. cst上来敲K,WA ...

  3. POJ1068 Parencodings 解题报告

    Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...

  4. Path Sum(参考别人,二叉树DFS)

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...

  5. 数据库可视化操纵软件有navicat和sqlyog

    数据库可视化操纵软件有navicat和sqlyog 数据库可视化操纵软件有navicat和sqlyog

  6. 关于 TCP 并发连接的几个思考题与试验

    http://blog.csdn.net/solstice/article/details/6579232

  7. 滚动载入server端内容——样例

    网页代码例如以下 <!doctype html> <html> <head> <meta charset="utf-8"> < ...

  8. 如何在其他js 引入main.js 中 vue 的实例?

    1.原因解析 经测试发现,代码先执行了 index.js >>  main.js >> Home.vue scr/api/index.js src/main.js src/co ...

  9. 深度学习-theano-windows -cuda-环境搭建

    本文将具体介绍深度学习之cuda的环境搭建 工具:支持CUDA的显卡(安装cuda6.5),VS2013.Anaconda. 步骤: 1.安装cuda6.5 这个不具体介绍,网上有很多文章.注意选择你 ...

  10. SP2-0734: 未知的命令开头 &quot;imp scott/...&quot; - 忽略了剩余的行。

    Oracle数据导入报错:SP2-0734: 未知的命令开头 "imp scott/..." - 忽略了剩余的行. 原因:进入sqlplus里是不能运行imp的(sqlplus不认 ...