manacher算法学习(求最长回文子串长度)
Manacher总结
我的代码
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<ctime>
#include<queue>
#include<stack>
#include<vector>
#define rg register
#define il inline
#define lst long long
#define ldb long double
#define N 51000100
using namespace std;
const int Inf=1e9;
int n,ans=1;
int p[N];
char S[N],s[N<<1];
il int read()
{
rg int s=0,m=0;rg char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')m=1;ch=getchar();}
while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
return m?-s:s;
}
il void change()
{
s[0]=s[1]='#';
for(rg int i=0;i<n;++i)
{
s[(i<<1)+2]=S[i];
s[(i<<1)+3]='#';
}
s[n=(n<<1)+2]=0;
}
il void manacher()
{
rg int mx=0,id;
for(rg int i=1;i<n;++i)
{
if(i<mx)p[i]=min(p[(id<<1)-i],mx-i);
else p[i]=1;
while(s[i+p[i]]==s[i-p[i]])p[i]++;
if(p[i]+i>mx)
mx=p[i]+i,id=i;
}
}
int main()
{
cin>>S;
n=strlen(S);
change();
manacher();
for(rg int i=0;i<n;++i)
ans=max(ans,p[i]);
printf("%d\n",ans-1);
return 0;
}
题单(xzy,都是xzy的没错)
- [x] [luogu3805]【模板】manacher算法 https://www.luogu.org/problemnew/show/P3805
- [ ] [BZOJ3790]神奇项链 http://172.40.25.127:5283/problem/113790
- [ ] [SHOI2011]双倍回文 https://www.luogu.org/problemnew/show/P4287
- [ ] [ZJOI2009]对称的正方形 https://www.luogu.org/problemnew/show/P2601
- [ ] [luogu1659][国家集训队]拉拉队排练 https://www.luogu.org/problemnew/show/P1659
- [ ] [luogu4555]最长双回文串 https://www.luogu.org/problemnew/show/P4555
- [ ] [BZOJ3160]万径人踪灭 https://www.luogu.org/problemnew/show/P4199
manacher算法学习(求最长回文子串长度)的更多相关文章
- manacher算法_求最长回文子串长度
很好的总结,转自: http://blog.csdn.net/dyx404514/article/details/42061017 总结为:两大情况,三小情况. 两大情况:I. i <= p 1 ...
- Manacher模板( 线性求最长回文子串 )
模板 #include<stdio.h> #include<string.h> #include<algorithm> #include<map> us ...
- Manacher算法讲解——字符串最长回文子串
引 入 引入 引入 Manachar算法主要是处理字符串中关于回文串的问题的,这没什么好说的. M a n a c h e r 算 法 Manacher算法 Manacher算法 朴素 求一个字符串中 ...
- 【Manacher算法】求最长回文串的优秀算法
先贴一下代码~ //by 减维 #include<cstdio> #include<iostream> #include<cstring> #include< ...
- [hdu 3068] Manacher算法O(n)最长回文子串
一个不错的讲解:https://github.com/julycoding/The-Art-Of-Programming-By-July/blob/master/ebook/zh/01.05.md # ...
- Manacher 求最长回文子串算法
Manacher算法,是由一个叫Manacher的人在1975年发明的,可以在$O(n)$的时间复杂度里求出一个字符串中的最长回文子串. 例如这两个回文串“level”.“noon”,Manacher ...
- Manacher算法(马拉车)求最长回文子串
Manacher算法求最长回文字串 算法思路 按照惯例((・◇・)?),这里只是对算法的一些大体思路做一个描述,因为找到了相当好理解的博客可以参考(算法细节见参考文章). 一般而言,我们的判断回文算法 ...
- Manacher算法:求解最长回文字符串,时间复杂度为O(N)
原文转载自:http://blog.csdn.net/yzl_rex/article/details/7908259 回文串定义:"回文串"是一个正读和反读都一样的字符串,比如&q ...
- hihoCoder #1032 : 最长回文子串 [ Manacher算法--O(n)回文子串算法 ]
传送门 #1032 : 最长回文子串 时间限制:1000ms 单点时限:1000ms 内存限制:64MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相 ...
随机推荐
- 省电的iPhone定位
1.Getting the User’s Current Location 获取用户当前位置. 获取位置的方式有三种:GPS, cell tower triangulation(蜂窝站点), 和 Wi ...
- 2018-10-2-win10-uwp-win2d-特效
title author date CreateTime categories win10 uwp win2d 特效 lindexi 2018-10-02 21:20:46 +0800 2018-6- ...
- tf.reshape
tf.reshape(tensor, shape, name=None) 其中,tensor是向量,或者说矩阵 shape是转换后的向量,或者转换后的矩阵形状 [2,1]转换成二行一列 [2,-1]转 ...
- C# 给DataTable去重
using System; using System.Data; namespace DelegateTest { public class Program { public static void ...
- 18-基于双TMS320C6678 DSP的3U VPX的信号处理平台
基于双TMS320C6678 DSP的3U VPX的信号处理平台 一.板卡概述 板卡由我公司自主研发,基于3U VPX架构,处理板包含两片TI DSP TMS320C6678芯片:一片Xilinx公司 ...
- Windows安装Scrapy(转)
转自: http://www.nnzhp.cn/archives/558 Scrapy是python开发的一个爬虫框架,如果你要学习它的话,可能第一步在安装的时候,就会遇到很多问题,因为Scrapy很 ...
- [Luogu2014]选课(树形dp)
[Luogu2014]选课 题目描述 在大学里每个学生,为了达到一定的学分,必须从很多课程里选择一些课程来学习,在课程里有些课程必须在某些课程之前学习,如高等数学总是在其它课程之前学习.现在有N门功课 ...
- Google Capture The Flag 2018 (Quals) - Beginner's Quest - Reverse - Firmware
参考链接:https://ctftime.org/task/6263 题目 After unpacking the firmware archive, you now have a binary in ...
- Ubuntu apt-get install E: 无法定位软件包Ubuntu apt-get install E: 无法定位软件包
sudo cp /etc/apt/sources.list /etc/apt/sources.list-bak #先将之前的source-list备份 sudo vi /etc/apt/sources ...
- python 日期封装
import time import datetime import locale class TimeUtil: def __init__(self, curtime=None): self.cur ...