poj3974(manacher)
传送门:Palindrome
题意:给定一个字符串,求最长回文子串。
分析:manach裸题,核心理解mx>i?p[i]=min(p[2*id-i],mx-i):1.
#pragma comment(linker,"/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-6
#define N 1000010
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PII pair<int,int>
using namespace std;
inline LL read()
{
char ch=getchar();LL x=,f=;
while(ch>''||ch<''){if(ch=='-')f=-;ch=getchar();}
while(ch<=''&&ch>=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int p[N<<],ans,len,num,mx,id;
char s[N],str[N<<];
void build()
{
len=strlen(s);num=;
str[num++]='@';str[num++]='#';
for(int i=;i<len;i++)
{
str[num++]=s[i];
str[num++]='#';
}
str[num]=;
}
void manacher()
{
ans=;mx=;
memset(p,,sizeof(p));
for(int i=;i<num;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;
if(ans<p[i]-)ans=p[i]-;
}
}
int main()
{
int cas=;
while(scanf("%s",s)>)
{
if(strcmp(s,"END")==)break;
build();
manacher();
printf("Case %d: %d\n",cas++,ans);
}
}
poj3974(manacher)的更多相关文章
- 【学习笔记】字符串—马拉车(Manacher)
[学习笔记]字符串-马拉车(Manacher) 一:[前言] 马拉车用于求解连续回文子串问题,效率极高. 其核心思想与 \(kmp\) 类似:继承. --引自 \(yyx\) 学姐 二:[算法原理] ...
- O(n)回文子串(Manacher)算法
O(n)回文子串(Manacher)算法 资料来源网络 参见:http://www.felix021.com/blog/read.php?2040 问题描述: 输入一个字符串,求出其中最大的回文子串. ...
- HDU 4513 吉哥系列故事——完美队形II(Manacher)
Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成 ...
- 牛客小白月赛13 小A的回文串(Manacher)
链接:https://ac.nowcoder.com/acm/contest/549/B来源:牛客网 题目描述 小A非常喜欢回文串,当然我们都知道回文串这种情况是非常特殊的.所以小A只想知道给定的一个 ...
- 2018.06.30 BZOJ 2342: [Shoi2011]双倍回文(manacher)
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 128 MB Description Input 输入分为两行,第一行为一个整数,表示字符串 ...
- HDU----(3294)Girls' research(manacher)
Girls' research Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)T ...
- 最长回文(Manacher)
HOT~ 杭电2015级新生如何加入ACM集训队? 最长回文 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- CC 3-Palindromes(manacher)
传送门:3-Palindromes 题意:求为回文串且能整除3且不前导0的子串个数. 分析:由 manacher算法O(N)可算出以i为坐标的最长为p[i]回文子串,且Si-k,Si-k+1..... ...
- HDU - 3068 最长回文(manacher)
HDU - 3068 最长回文 Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Subm ...
随机推荐
- JQuery5.04获取
获取body: $('body'); 或者 $(document.body); 获取元素标签:$('div'); $('a'); 获取ID: $('id'); 获取某个元素的某个属性: $('a ...
- ORACLE11.2.0 SQLPLUS 报 error while loading shared libraries
相应的环境平台: OS: Linux TEST11G 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:21 EST 2007 i686 i686 i386 GNU/Linux ...
- HDU 1425 sort 题解
选择出数列中前k个最大的数. 这里由于数据特殊.所以能够使用hash表的方法: #include <cstdio> #include <algorithm> #include ...
- U盘安装Ubuntu kylin版
初试U盘安装Ubuntu14.04 kylin版 等待Ubuntu14.04 kylin版出来后,一直想要尝试在物理机进行安装体验,恰巧碰到五一假期,因为咱是穷人,没钱出去玩,所以就有了时间实地进行 ...
- TODO管理工具TaskWarrior (跨平台C++代码)
Taskwarrior 是一个基于命令行的 TODO 列表管理工具.主要功能包括:标签.彩色表格输出.报表和图形.大量的命令.底层API.多用户文件锁等功能. http://www.oschina.n ...
- 基于visual Studio2013解决面试题之0807strstr函数
题目
- 在webx.ml中 配置struts2 后 welcome-file-list 失效的解决办法
struts2 <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.a ...
- 一些实用的mysql语句(不断积累更新)
1.数据表里仅仅有生日字段,想计算出其年龄的mysql语句: SELECT *,DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW( ))-TO_DAYS(生日字段)),'%Y')+0 ...
- bonjour
首先bonjour并非必须的,可是它的确非常方便,假设没有它我们须要指定ip地址进行局域网的传输,有了它就能够依据服务的详细的名称来选择服务,能够这样来理解bonjour就相当于hostname,我们 ...
- mysql 分区和集群
集群和分区:http://han-zw.iteye.com/blog/1662941http://www.php-note.com/article/detail/794 分区:http://lober ...