题目传送门

 /*
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. MT6753/MT6755 呼吸灯功能添加

    利用mtk pmic自带的呼吸灯模式: 主要修改代码: kernel-3.10/drivers/misc/mediatek/leds/mt6755/leds.c   int mt_brightness ...

  2. hdu_1028_Ignatius and the Princess III

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  3. Test for Job 图上的动态规划(DAG)

    Test for Job Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 11399   Accepted: 2697 Des ...

  4. Eclipse错误:Syntax error on tokens, delete these tokens问题解决

    错误:Syntax error on tokens, delete these tokens 出现这样的错误一般是括号.中英文字符.中英文标点.代码前面的空格,尤其是复制粘贴的代码,去掉即可.

  5. C++进阶之虚函数表

    C++通过继承(inheritance)和虚函数(virtual function)来实现多态性.所谓多态,简单地说就是,将基类的指针或引用绑定到子类的实例,然后通过基类的指针或引用调用实际子类的成员 ...

  6. hiho一下 第五十一周(有向图欧拉路径)51

    //////////////////////////////////////////////////////////////////////////////////////////////////// ...

  7. Android API Guides –System Permissions

    系统权限 声明: 本文由Gordon翻译 公布于www.dlvoice.com 欢迎转载,但请保留此声明 原文地址:http://developer.android.com/guide/topics/ ...

  8. Python正則表達式小结(1)

    学习一段python正則表達式了, 对match.search.findall.finditer等函数作一小结  以下以一段网页为例,用python正則表達式作一个范例: strHtml = '''& ...

  9. LINQ实现

    public static IEnumerable<TSource> MyWhere<TSource>(     this IEnumerable<TSource> ...

  10. eventkeyboardmouse

    http://www.javascriptkit.com/jsref/eventkeyboardmouse.shtml