ACM题目————最长回文串
Description
回文就是正反读都是一样的字符串,如aba, abba等
Input
两组case之间由空行隔开(该空行不用处理)
字符串长度len <= 110000
Output
Sample Input
abab
Sample Output
3
用manacher算法求最长回文串长度。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <string>
#include <queue>
#define INF 10000001 using namespace std;
const int maxn = *;
char str[maxn];
int p[maxn]; void manacher(char *s, int len){
p[] = ;
int Max = , d= ;
for(int i=; i<len; i++){
p[i] = Max > i ? min(p[d*-i],Max-i): ;
while( s[i+p[i]] == s[i-p[i]]) p[i] ++ ;
if( i + p[i] > d + p[d] ){
d = i ;
Max = i + p[i] ;
}
}
} int main(){
while( ~ scanf("%s",str) ){
int len = strlen(str);
for(int i=len; i>=; i--){
str[(i<<)+] = '#' ;
str[(i<<)+] = str[i] ;
}
str[] = '*' ;
len = len * + ;
manacher(str,len);
int ans = ;
for(int i=; i<len; i++){
ans = max(p[i]-,ans);
}
printf("%d\n",ans);
}
return ;
}
ACM题目————最长回文串的更多相关文章
- 字符串的最长回文串:Manacher’s Algorithm
题目链接:Longest Palindromic Substring 1. 问题描述 Given a string S, find the longest palindromic substring ...
- Manacher's Algorithm 马拉车算法(求最长回文串)
作用:求一个字符串中的最长子串,同时还可以求所有子串的长度. 题目链接: https://vjudge.net/contest/254692#problem/B 最长回文串长度的代码: int Man ...
- (最长回文串 模板) 最长回文 -- hdu -- 3068
http://acm.hdu.edu.cn/showproblem.php?pid=3068 最长回文 Time Limit: 4000/2000 MS (Java/Others) Memory ...
- Hdu 3294 Girls' research (manacher 最长回文串)
题目链接: Hdu 3294 Girls' research 题目描述: 给出一串字符串代表暗码,暗码字符是通过明码循环移位得到的,比如给定b,就有b == a,c == b,d == c,.... ...
- Leetcode0005--Longest Palindromic Substring 最长回文串
[转载请注明]http://www.cnblogs.com/igoslly/p/8726771.html 来看一下题目: Given a string s, find the longest pali ...
- Manacher(输出最长回文串及下标)
http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit: 3000/1000 MS (Java/Others ...
- Manacher(最长回文串)
http://acm.hdu.edu.cn/showproblem.php?pid=3068 最长回文 Problem Description 给出一个只由小写英文字符a,b,c...y,z组成的字符 ...
- HDU 3068 最长回文 (Manacher最长回文串)
Problem Description 给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度.回文就是正反读都是一样的字符串,如aba, abba等 Input 输 ...
- leetcode 每日签到 409. 最长回文串
题目: 最长回文串 给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串. 在构造过程中,请注意区分大小写.比如 "Aa" 不能当做一个回文字符串. 注意: ...
随机推荐
- iOS开发 - 网络数据安全加密(MD5)
提交用户的隐私数据 一定要使用POST请求提交用户的隐私数据GET请求的所有参数都直接暴露在URL中请求的URL一般会记录在服务器的访问日志中服务器的访问日志是黑客攻击的重点对象之一 用户的隐私数据登 ...
- jquery实现input输入框实时输入触发事件代码
<input id="productName" name="productName" class="wid10" type=" ...
- NLS_LANG参数说明
NLS_LANG参数说明 格式: NLS_LANG = language_territory.charset 它有三个组成部分(语言.地域和字符集),每个成分控制了NLS子集的特性.其中: Lang ...
- openSuSE DNS SERVER CONFIG
system:openSuSE 12.3(much better and frendly than the 12.1 in network config)1,network config,attent ...
- Lintcode: Segment Tree Modify
For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in thi ...
- [原创]java WEB学习笔记88:Hibernate学习之路-- -Hibernate检索策略(立即检索,延迟检索,迫切左外连接检索)
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- HDU 1724 Ellipse(数值积分の辛普森公式)
Problem Description Math is important!! Many students failed in 2+2’s mathematical test, so let's AC ...
- CentOS 5.5 Nginx+JDK+MySQL+Tomcat(jsp)成功安装案例
在CentOS 5.5中安装Nginx+jdk+mysql+tomcat是非常容易的.只需yum安装环境包和nginx.解压安装jdk和tomcat.配置profile文件.server.xml和ng ...
- paper 40 :鲁棒性robust
最近只想安心.安静的科研,不想被任何人打扰,继续做自己,不忘初心,方得始终! 首先了解下鲁棒性这个词的定义.鲁棒性是指控制系统在一定(结构,大小)的参数摄动下,维持某些性能的特性.根据对性能的不同定义 ...
- Oracle中的MD5加密
一.技术点 1. DBMS_OBFUSCATION_TOOLKIT.MD5 DBMS_OBFUSCATION_TOOLKIT.MD5是MD5编码的数据包函数,但偶在使用select DBMS_OBFU ...