1089 最长回文子串 V2(Manacher算法) 

基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题

 收藏

 关注

回文串是指aba、abba、cccbccc、aaaa这种左右对称的字符串。

输入一个字符串Str,输出Str里最长回文子串的长度。

Input

输入Str(Str的长度 <= 100000)

Output

输出最长回文子串的长度L。

Input示例

daabaac

Output示例

5
#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<algorithm>
#include<stack>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=110010;
char Ma[maxn*2];
int Mp[maxn*2];
void Manacher(char s[],int len)
{
int l=0;
Ma[l++]='$';
Ma[l++]='#';
for(int i=0;i<len;i++)
{
Ma[l++]=s[i];
Ma[l++]='#';
}
Ma[l]=0;
int mx=0,id=0;
for(int i=0;i<l;i++)
{
Mp[i]=mx>i?min(Mp[2*id-i],mx-i):1;
while(Ma[i+Mp[i]]==Ma[i-Mp[i]])Mp[i]++;
if(i+Mp[i]>mx)
{
mx=i+Mp[i];
id=i;
}
}
}
char s[maxn];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLIN
while(scanf("%s",s)==1)
{
int len=strlen(s);
Manacher(s,len);
int ans=0;
for(int i=0;i<2*len+2;i++)
ans=max(ans,Mp[i]-1);
printf("%d\n",ans);
}
return 0;
}

最新文章

  1. (转)配置Log4j(很详细)
  2. easyUI学习笔记之tab组件的鼠标事件
  3. 【python】list,dict赋值不要用等号,要用extend,update
  4. bzoj 1588: [HNOI2002]营业额统计 treap
  5. IntelliJ IDEA 中properties中文显示问题
  6. python 生成二维码
  7. 【Node.app】Node.js for iOS
  8. 配置phpmyadmin使登录时可填写IP管理多台MySQL 连接多个数据库 自动登录
  9. iOS中打印系统详细日志
  10. Qt对话框_模态/非模态
  11. Mysql主从复制读写分离
  12. index-document-shard
  13. Pytorch中的Batch Normalization操作
  14. PHP中两个冒号是什么意思
  15. poj1679
  16. Vue03
  17. 34.Find First and Last Position of Element in Sorted Array---头条面试题、《剑指offer》38
  18. nmap速查表v1.0
  19. 怎样在QML应用中创建一个Context Menu
  20. [android] 两种异步方式

热门文章

  1. 完全删除MySQL及相关软件
  2. 2019年8月22日 星期四(怎样成为PHP大牛)
  3. 从入门到自闭之Python列表,元祖及range
  4. python 操作mongodb 文件相关
  5. 如何在LinuxKernel中操作file(set_fs與get_fs)
  6. 为什么说Python采用的是基于值的内存管理模式?
  7. MySQL的变量
  8. CF1151F Sonya and Informatics
  9. 让图表的Y轴 产生几个刻度距离
  10. C# 之 String.Empty