hdu3068 manacher模板题
回文就是正反读都是一样的字符串,如aba, abba等
Input输入有多组case,不超过120组,每组输入为一行小写英文字符a,b,c...y,z组成的字符串S
两组case之间由空行隔开(该空行不用处理)
字符串长度len <= 110000Output每一行一个整数x,对应一组case,表示该组case的字符串中所包含的最长回文长度.
Sample Input
aaaa abab
Sample Output
4
3
题意:找最长回文子串
题解:manacher算法,据说这是一道连后缀数组O(nlogn)也卡的神题。。结果真的是,第一次用manacher写也tle了,估计是写搓了改了好几遍
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 10007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=(<<)-,inf=0x3f3f3f3f; string str;
int p[N],slen; void manacher()
{
int mx=,id;
for(int i=;i<=slen;i++)
{
if(mx>i)p[i]=min(p[*id-i],mx-i);
else p[i]=;
while(str[i+p[i]]==str[i-p[i]])p[i]++;
if(p[i]+i>mx)
{
mx=p[i]+i;
id=i;
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
// cout<<setiosflags(ios::fixed)<<setprecision(2);
string s;
int cnt=;
while(cin>>s){
str="$#";
for(int i=;i<s.size();i++)
{
str+=s[i];
str+="#";
}
slen=str.size();
memset(p,,sizeof p);
manacher();
int ans=-;
for(int i=;i<str.size();i++)
ans=max(ans,p[i]-);
cout<<ans<<endl;
}
return ;
}
hdu3068 manacher模板题的更多相关文章
- HDU 3068 最长回文( Manacher模板题 )
链接:传送门 思路:Manacher模板题,寻找串中的最长回文子串 /***************************************************************** ...
- ural 1297 Palindrome(Manacher模板题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 求最长回文子串. http://acm.timus.ru/problem.aspx ...
- 最长回文 HDU - 3068 manacher 模板题
题意:找串的最长回文字串(连续) 题解:manacher版题 一些理解:首位加上任意两个字符是为了判断边界. 本算法主要是为了 1.省去奇偶分类讨论. 2.防止形如aaaaaaa的串使得暴力算法蜕化为 ...
- HDU 3068 最长回文(manacher模板题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068 题目大意:求字符串s中最长的回文子串 解题思路:manacher模板 代码 #include&l ...
- HDU3068:最长回文(Manacher模板)
最长回文 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu3068 最长回文 马拉车模板题
题目传送门 马拉车算法模板题. 学习博客 #include<bits/stdc++.h> #define clr(a,b) memset(a,b,sizeof(a)) using name ...
- Manacher模板( 线性求最长回文子串 )
模板 #include<stdio.h> #include<string.h> #include<algorithm> #include<map> us ...
- [AHOI 2009] 维护序列(线段树模板题)
1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小 ...
- HDU 2222 AC自动机模板题
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...
随机推荐
- linux基础命令---bzip2
bzip2 使用Burrows-Wheeler块排序文本压缩算法,将文件进行压缩,压缩比率比一般算法高一些.bzip2要求命令行标志附带一个文件名列表.每个文件都被自己的压缩版本替换,名称为“orig ...
- Linux服务器---apache配置文件
Apache配置文件 Apache的配置文件默认路径是“/etc/httpd/conf/httpd.conf”,编辑该文件就可以修改Apache的配置 1.设置网页主目录,参数DocumentRoot ...
- keepalived+lvs高可用集群
LVS+Keepalived 介绍 LVS LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国 ...
- 在uboot中加入cmd_run命令,运行环境变量
在学习uboot的过程中会经常烧录程序,每次都要敲一些下载指令.这样是不是很麻烦,有什么办法能快速的烧写呢.很简单,将需要敲击的指令编译到uboot中,以环境变量的形式存在.但是环境变量很好加,如何运 ...
- mysql-innodb的事务日志
[参考书籍:mysql技术内幕 INNODB存储引擎][参考了一些博客内容] 事务的隔离性由锁机制来实现,事务的原子性,一致性,持久性通过INNODB的redo log和undo log来完成. re ...
- Linux解压文件到指定目录
Linux解压文件到指定目录 tar在Linux上是常用的打包.压缩.加压缩工具,他的参数很多,折里仅仅列举常用的压缩与解压缩参数 参数:-c :create 建立压缩档案的参数:-x : 解压缩压缩 ...
- 05:ModelForm 数据验证 & 生成html & 数据库操作
目录:Django其他篇 01:Django基础篇 02:Django进阶篇 03:Django数据库操作--->Model 04: Form 验证用户数据 & 生成html 05:Mo ...
- C语言程序设计实习报告
C语言程序设计实习报告 简介 语言实践心得体会范文在科技高度发展的今天,计算机在人们之中的作用越来越突出.而c语言作为一种计算机的语言,我们学习它,有助于我们更好的了解计算机,与计算机进行交流,因此, ...
- node包管理工具--nvm(windows)
windows 安装nvw-windows 使用nvm工具: windows使用nvm-noinstall.zip安装 nvm-noinstall.zip 这个是绿色免安装版本,但是使用之前需要配置 ...
- Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心
After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...