Palindrome---poj3974(最大回文子串manacher)
题目链接:http://poj.org/problem?id=3974
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N = 2e6+; int p[N];
char s[N];
int Manacher(char s[], int n)
{
int Id=, mx = , ans = ;
for(int i=; i<n; i++)
{
if(mx > i)
p[i] = min(p[Id*-i], mx-i);
else
p[i] = ;
while(s[i+p[i]] == s[i-p[i]])
p[i]++;
if(mx < p[i]+i)
{
mx = p[i]+i;
Id = i;
}
ans = max(ans, p[i]);
}
return ans - ;
}
int main()
{
int t=;
while(scanf("%s", s),strcmp(s, "END"))
{
int len = strlen(s);
for(int i=len; i>=; i--)
{
s[i+i+] = s[i];
s[i+i+] = '#';
}
s[] = '$';
int ans = Manacher(s, *len+);
printf("Case %d: %d\n", t++, ans);
}
return ;
}
Palindrome---poj3974(最大回文子串manacher)的更多相关文章
- 最长回文子串——manacher
最长回文子串--Manacher 算法 (原版的博主的代码都是用py写的,这里改成c++) c++ 算法 字符串处理 0. 问题定义 最长回文子串问题:给定一个字符串,求它的最长回文子串长度. 如果一 ...
- 九度OJ 1528 最长回文子串 -- Manacher算法
题目地址:http://ac.jobdu.com/problem.php?pid=1528 题目描述: 回文串就是一个正读和反读都一样的字符串,比如"level"或者"n ...
- lintcode最长回文子串(Manacher算法)
题目来自lintcode, 链接:http://www.lintcode.com/zh-cn/problem/longest-palindromic-substring/ 最长回文子串 给出一个字符串 ...
- 最长回文子串Manacher算法模板
Manacher算法能够在O(N)的时间复杂度内得到一个字符串以任意位置为中心的回文子串.其算法的基本原理就是利用已知回文串的左半部分来推导右半部分. 首先,在字符串s中,用rad[i]表示第i个字符 ...
- URAL 1297 Palindrome 最长回文子串
POJ上的,ZOJ上的OJ的最长回文子串数据量太大,用后缀数组的方法非常吃力,所以只能挑个数据量小点的试下,真要做可能还是得用manacher.贴一下代码 两个小错,一个是没弄懂string类的sub ...
- 最长回文子串—Manacher 算法 及 python实现
最长回文子串问题:给定一个字符串,求它的最长回文子串长度.如果一个字符串正着读和反着读是一样的,那它就是回文串. 给定一个字符串,求它最长的回文子串长度,例如输入字符串'35534321',它的最 ...
- hihocoder #1032 : 最长回文子串 Manacher算法
题目链接: https://hihocoder.com/problemset/problem/1032?sid=868170 最长回文子串 时间限制:1000ms内存限制:64MB 问题描述 小Hi和 ...
- Girls' research---hdu3294(回文子串manacher)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3294 给出一个字符串和加密的字符规律 例如 c abcba c代表把串中的c改成a,d改成b... b ...
- 5. Longest Palindromic Substring(最长回文子串 manacher 算法/ DP动态规划)
Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...
- HiHo 1032 最长回文子串 (Manacher算法求解)
/** * 求解最长回文字串,Manacher算法o(n)求解最长回文子串问题 **/ #include<cstdio> #include<cstdlib> #include& ...
随机推荐
- 在容器中使用erase函数,迭代器的处理
在c++编程中,用到迭代器的时候,往往不知道如何删除当前迭代器指向的元素. erase函数: 返回下一个迭代器. 只使用vector的erase函数,记住,该函数是迭代器失效,返回下一个迭代器. ...
- hdu 1006 Tick and Tick 有技巧的暴力
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- [转]VC传递消息sendmessage
SendMessage的基本结构如下: SendMessage( HWND hWnd, //消息传递的目标窗口或线程的句柄. UINT Msg, //消息类别(这里可以是一些系统消息,也可以是自己定 ...
- jQuery:(一)jQuery简介
一.jQuery简介jQuery由美国人John Resig于2006年创建jQuery是目前最流行的JavaScript程序库,它是对JavaScript对象和函数的封装. 二.jQuery的优势1 ...
- ThinkPHP 汉字转成多种形式拼音
模型: <?php namespace Admin\Model; use Think\Model; /** * 汉字转拼音 * @author huangguojin */ class ZHMo ...
- [android] android 获取网络连接信息
效果图: 工具类 /** * 获取网络连接信息 * * 根据NetworkInfo可以知道有很多的连接方式和信息 * * ① 当没有任何可用网络的时候,networkinfo为null 判断netw ...
- (转)zero copy原理
转自: http://blog.csdn.net/zzz_781111/article/details/7534649 Zero Copy 简介 许多web应用都会向用户提供大量的静态内容,这意味着有 ...
- VS编译错误:fatal error C1859:unexpected precompiled header error, simply rerunning the compiler might fix this problem
fatal error C1859:unexpected precompiled header error, simply rerunning the compiler might fix this ...
- 简单脱壳教程笔记(8)---手脱EZIP壳
本笔记是针对ximo早期发的脱壳基础视频教程,整理的笔记.本笔记用到的工具下载地址: http://download.csdn.net/detail/obuyiseng/9466056 EZIP壳 : ...
- Hibernate_day04--QBC查询
QBC查询 1 使用hql查询需要写hql语句实现,但是使用qbc时候,不需要写语句了,使用方法实现 2 使用qbc时候,操作实体类和属性 3 使用qbc,使用Criteria对象实现 查询所有 1 ...