昨晚的bc做得好忧郁-----

第一题改了好久好久好久----等改完发现比赛已经结束了(发现是枚举子集的位运算那儿写错了--)

第二题是判断能否将一个字符串划分成三段回文串

今天学了一点点  Manacher

http://wenku.baidu.com/view/3031d2d3360cba1aa811da42.html

模板大概是这样的--

 void Manacher(){
for(int i = ;i <= len;i++){
t[*i-] = '#';
t[*i] = s[i];
}
t[] = '?';t[len*+] = '#';
t[*len+] = '\0';
int tmax = ,id = ;
len = len* + ;
for(int i = ;i <= len;i++){
if(tmax > i) p[i] = min(p[*id-i],tmax-i);
else p[i] = ;
while(t[i-p[i]] == t[i+p[i]]) p[i]++;
if(i+p[i] > tmax){
tmax = i+p[i];
id = i;
}
}
}

hdu 3068

求最长回文串

 #include <cstdio>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std; #define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MP(a,b) make_pair(a,b)
#define PB push_back typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-;
const int INF = ( << ) - ;
const int maxn = *; char s[maxn];
char t[maxn];
int p[maxn]; void Manacher(){
int len = strlen(s+);
for(int i = ;i <= len;i++){
t[*i-] = '#';
t[*i] = s[i];
}
t[] = '?';
t[*len+] = '#';
t[*len+] = '\0';
int tmax = ,id = ;
int ans = ;
len = *len + ;
for(int i = ;i <= len;i++){
if(tmax > i) p[i] = min(p[*id-i],tmax-i);
else p[i] = ;
while(t[i-p[i]] == t[i+p[i]]) p[i]++;
if(i+p[i] > tmax){
tmax = i+p[i];
id = i;
}
ans = max(ans,p[i]);
}
printf("%d\n",ans-);
} int main(){
while(scanf("%s",s+) != EOF){
Manacher();
}
return ;
}

hdu 5340

先用一遍Manacher

然后如果从1到这个位置是回文串的话,把这个位置加进L[]数组

如果从这个位置到结尾是回文串的话,把这个位置加进R[]数组

再枚举L,R,判断L---R这个区间是不是回文串

判断方法就是看一下,这个区间的中点的p[i]能否覆盖这个中间部分---

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std; const int maxn = ; char s[maxn],t[maxn];
int p[maxn],L[maxn],R[maxn];
int len; void Manacher(){
for(int i = ;i <= len;i++){
t[*i-] = '#';
t[*i] = s[i];
}
t[] = '?';t[len*+] = '#';
t[*len+] = '\0';
int tmax = ,id = ;
len = len* + ;
for(int i = ;i <= len;i++){
if(tmax > i) p[i] = min(p[*id-i],tmax-i);
else p[i] = ;
while(t[i-p[i]] == t[i+p[i]]) p[i]++;
if(i+p[i] > tmax){
tmax = i+p[i];
id = i;
}
}
} bool solve(){
Manacher();
int l = ,r = ;
int length = strlen(s+);
for(int i = ;i <= len-;i++){
if(i - p[i] == ) L[l++] = i;
if(i + p[i] == len+) R[r++] = i;
} for(int i = ;i < l;i++){
for(int j = r-;j >= ;j--){
// printf("R[%d] = %d ",j,R[j]);
int lb = L[i] + p[L[i]],ub = R[j] - p[R[j]];
if(lb > ub) break;
int mid = (lb + ub)/;
// printf("lb = %d ub = %d mid = %d\n",lb,ub,mid);
if(p[mid] > mid - lb) return true;
}
}
return false;
} int main(){
int T;
scanf("%d",&T);
while(T--){
memset(p,,sizeof(p));
scanf("%s",s+);
len = strlen(s+);
if(solve()) printf("Yes\n");
else printf("No\n");
}
return ;
}

题解的暴力压位还是不会的说啊~~~

___Manacher(线性回文子串处理算法)的更多相关文章

  1. 九度OJ 1528 最长回文子串 -- Manacher算法

    题目地址:http://ac.jobdu.com/problem.php?pid=1528 题目描述: 回文串就是一个正读和反读都一样的字符串,比如"level"或者"n ...

  2. lintcode最长回文子串(Manacher算法)

    题目来自lintcode, 链接:http://www.lintcode.com/zh-cn/problem/longest-palindromic-substring/ 最长回文子串 给出一个字符串 ...

  3. 最长回文子串Manacher算法模板

    Manacher算法能够在O(N)的时间复杂度内得到一个字符串以任意位置为中心的回文子串.其算法的基本原理就是利用已知回文串的左半部分来推导右半部分. 首先,在字符串s中,用rad[i]表示第i个字符 ...

  4. 最长回文子串—Manacher 算法 及 python实现

    最长回文子串问题:给定一个字符串,求它的最长回文子串长度.如果一个字符串正着读和反着读是一样的,那它就是回文串.   给定一个字符串,求它最长的回文子串长度,例如输入字符串'35534321',它的最 ...

  5. hihocoder #1032 : 最长回文子串 Manacher算法

    题目链接: https://hihocoder.com/problemset/problem/1032?sid=868170 最长回文子串 时间限制:1000ms内存限制:64MB 问题描述 小Hi和 ...

  6. 5. Longest Palindromic Substring(最长回文子串 manacher 算法/ DP动态规划)

    Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...

  7. HiHo 1032 最长回文子串 (Manacher算法求解)

    /** * 求解最长回文字串,Manacher算法o(n)求解最长回文子串问题 **/ #include<cstdio> #include<cstdlib> #include& ...

  8. hihoCoder #1032 : 最长回文子串 [ Manacher算法--O(n)回文子串算法 ]

    传送门 #1032 : 最长回文子串 时间限制:1000ms 单点时限:1000ms 内存限制:64MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相 ...

  9. 51nod1089 最长回文子串 manacher算法

    0. 问题定义 最长回文子串问题:给定一个字符串,求它的最长回文子串长度. 如果一个字符串正着读和反着读是一样的,那它就是回文串.下面是一些回文串的实例: 12321 a aba abba aaaa ...

随机推荐

  1. 简明git教程(单人版本)

    最近开始写一个比较大的东西,所以需要用到git,之前一直在用金山快盘和乌龟搭建的SVN,最近想尝试一下git 1.安装 Ubuntu: sudo apt-get install git 老版本的Ubu ...

  2. 洛谷P2827 蚯蚓 队列 + 观察

    我们不难发现先被切开的两半一定比后被切开的两半大,这样就天然的生成了队列的单调性,就可以省去一个log.所以,我们开三个队列,分别为origin,big,smallorigin, big, small ...

  3. 一个很好的JS,ASP二级下拉框联动。

    在我们制作网站会员注册信息时,一般会涉及到填写自己所在省/市,如果用input或textarea做成填写形式不太理想.所以大部分网站都会选择联动下来列表形式,做起来也不算很复杂,同时看上去也很轻松. ...

  4. 用SufaceGO加微软全家桶做个遥控车(一)

    作为一个dotnet技术的新手我是不好意思写帖子的,原因就是本人技术太水了,写出的帖子肯定会让人笑话.所以这次我是厚着脸皮写出这个帖子的,希望大佬们轻喷了.我的目标就是用SurfaceGo实现一个和我 ...

  5. BZOJ 3774 最优选择 (最小割+二分图)

    题面传送门 题目大意:给你一个网格图,每个格子都有$a_{ij}$的代价和$b_{ij}$的回报,对于格子$ij$,想获得$b_{ij}$的回报,要么付出$a_{ij}$的代价,要么$ij$周围四联通 ...

  6. ThinkPHP3.1.3分表状态时候的自动验证的代码BUG

    问题描述 ThinkPHP3.1.3 当使用TP的分库分表后 有些地方需要使用Model自动验证create,当验证唯一性unique会出现BUG, 具体描述 因为自动验证检测唯一性会使用隐式的使用f ...

  7. docker 下载镜像 ( 以 mysql为例 )

    一.官方镜像仓库 https://hub.docker.com/explore/ 二.常用操作 三.使用命令查看 mysql [root@localhost fw]# docker search my ...

  8. redis 零散知识

    1.单线程 2.默认 16 个库.0~15 3.select :切换数据库 4.DBsize :查看当前数据库的数量 5.keys * :查看当前库的所有 key 6.keys k? :问号是占位符 ...

  9. Java并发之线程间的同步协作与通信协作

    1,Monitor监视器与syncrhoized实现原理 1.1:Monitor Monitor是一个同步工具,相当于操作系统中的互斥量(mutex),即值为1的信号量. 它内置与每一个Object对 ...

  10. 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries

    CRB and Queries Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...