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: ...
随机推荐
- SQL锁机制和事务隔离级别
摘自:http://www.cnblogs.com/haiyang1985/archive/2009/02/27/1399641.html 锁机制 NOLOCK和READPAST的区别. 1. ...
- TED #08# Learn to read Chinese ... with ease!
ShaoLan: Learn to read Chinese ... with ease! Pre-requisites calligraphermy most treasured memoriesw ...
- P4180 【模板】严格次小生成树[BJWC2010]
P4180 [模板]严格次小生成树[BJWC2010] 倍增(LCA)+最小生成树 施工队挖断学校光缆导致断网1天(大雾) 考虑直接枚举不在最小生成树上的边.但是边权可能与最小生成树上的边相等,这样删 ...
- 20145101《Java程序设计》第三周学习总结
20145101 <Java程序设计>第3周学习总结 教材学习内容总结 本周进行的是第四章和第五章的学习.本阶段的学习难度有所提升,无论是在知识的量还是深度都开始增加,内容很丰富,也很有趣 ...
- 20145335郝昊《网络攻防》Exp5 MS08_067漏洞测试
20145335郝昊<网络攻防>Exp5 MS08_067漏洞测试 实验内容 了解掌握metasploit平台的一些基本操作,能学会利用已知信息完成简单的渗透操作. 漏洞MS08_067: ...
- tensorflow 生成随机数 tf.random_normal 和 tf.random_uniform 和 tf.truncated_normal 和 tf.random_shuffle
____tz_zs tf.random_normal 从正态分布中输出随机值. . <span style="font-size:16px;">random_norma ...
- UVa 12661 Funny Car Racing - spfa
很简单的一道最短路问题.分情况处理赛道的打开和关闭. Code /** * UVa * Problem#12661 * Accepted * Time:50ms */ #include<iost ...
- 如何让VS2012编写的程序在XP下运行
Win32主程序需要以下设置 第一步:在工程属性General设置 第二步:在C/C++ Code Generation 设置 第三步:SubSystem 和 Minimum Required Ve ...
- Python3基础 delattr 删除对象的属性
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 搭建最新版本的Android开发环境
只为成功找方法,不为失败找借口! Android开发学习总结(一)——搭建最新版本的Android开发环境 最近由于工作中要负责开发一款Android的App,之前都是做JavaWeb的开发,Andr ...