hihocoder1302 最长回文子串
先贴代码
所有的上面的提示已经交代的好清楚了……
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
const double ESP = 10e-;
const int MOD = +;
const int MAXN = +; char Str[MAXN];
char str[MAXN<<];
int f[MAXN<<]; int main(){
// freopen("input.txt","r",stdin);
// ios::sync_with_stdio(false);
int t;
scanf("%d",&t);
while(t--){
scanf("%s",Str);
int len = strlen(Str);
int n = ;
str[n++] = '$';
str[n++] = '#';
for(int i = ;i < len;i++){
str[n++] = Str[i];
str[n++] = '#';
}
//f[i]真正的回文子串长度+1,也是当前回文串的一半长度+1
str[n] = '\0';
int ans = ;
int mx = ; //不是回文子串的下一个位置
int j;
for(int i = ;i < n;i++){
if(mx > i){
f[i]=min(mx-i,f[*j-i]);
}else{
f[i] = ;
}
while(str[i-f[i] ]==str[i+f[i] ]){
f[i]++;
}
if(f[i]+i > mx){
mx = f[i]+i;
j = i;
}
ans = max(f[i]-,ans); }
printf("%d\n",ans);
}
return ;
}
hihocoder1302 最长回文子串的更多相关文章
- 最长回文子串-LeetCode 5 Longest Palindromic Substring
题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...
- 最长回文子串(Longest Palindromic Substring)
这算是一道经典的题目了,最长回文子串问题是在一个字符串中求得满足回文子串条件的最长的那一个.常见的解题方法有三种: (1)暴力枚举法,以每个元素为中心同时向左和向右出发,复杂度O(n^2): (2)动 ...
- lintcode最长回文子串(Manacher算法)
题目来自lintcode, 链接:http://www.lintcode.com/zh-cn/problem/longest-palindromic-substring/ 最长回文子串 给出一个字符串 ...
- 1089 最长回文子串 V2(Manacher算法)
1089 最长回文子串 V2(Manacher算法) 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 回文串是指aba.abba.cccbccc.aaaa ...
- 51nod1089(最长回文子串之manacher算法)
题目链接: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1089 题意:中文题诶~ 思路: 我前面做的那道回文子串的题 ...
- 求最长回文子串:Manacher算法
主要学习自:http://articles.leetcode.com/2011/11/longest-palindromic-substring-part-ii.html 问题描述:回文字符串就是左右 ...
- [译+改]最长回文子串(Longest Palindromic Substring) Part II
[译+改]最长回文子串(Longest Palindromic Substring) Part II 原文链接在http://leetcode.com/2011/11/longest-palindro ...
- [译]最长回文子串(Longest Palindromic Substring) Part I
[译]最长回文子串(Longest Palindromic Substring) Part I 英文原文链接在(http://leetcode.com/2011/11/longest-palindro ...
- Manacher's algorithm: 最长回文子串算法
Manacher 算法是时间.空间复杂度都为 O(n) 的解决 Longest palindromic substring(最长回文子串)的算法.回文串是中心对称的串,比如 'abcba'.'abcc ...
随机推荐
- UNIX网络编程5 POSIX 消息队列
<mqueue.h> mq_open mq_close mq_unlink mq_getattr/mq_setattr mq_send/mq_receive mq_notify sigwa ...
- graph isomorphism 开源算法库VFlib, Nauty
VFlib 开源算法库网站:http://www.cs.sunysb.edu/~algorith/implement/vflib/implement.shtml Nauty 开源算法库网站:http: ...
- 基于visual Studio2013解决C语言竞赛题之0202坐标转换
题目
- Problem 2169 shadow
Problem 2169 shadow Accept: 141 Submit: 421 Time Limit: 1000 mSec Memory Limit : 32768 KB Pr ...
- c++,public/protected/private权限修饰符
1.public的变量可以在类中以及外部访问到: 2. private只可以在类/友元中访问到. #include <iostream> using namespace std; //-- ...
- vim下设置tab
前言:大多数情况下tab键的宽度设置为4个空格,这个可以根据自己 的代码风格进行替换,然而当你提交不同的语言的代码的时候python 和c的时候就有区别了.c的话一般tab键做缩进,而python提交 ...
- postgresql文档生成注意事项
如果要生成中文版的postgresql,目前我所知道的方法见我的一篇博客http://www.cnblogs.com/codeblock/p/4812445.html 里面有详细的介绍,但是生成的文档 ...
- 利用phpmailer类邮件发送
<?php require("class.phpmailer.php"); //下载的文件必须放在该文件所在目录 $mail = new PHPMailer(); //建立邮 ...
- Python 第十三篇之一:前端页面 js和dome
一:JavaScript: JavaScript是一门编程语言,浏览器内置了JavaScript语言的解释器,所以在浏览器上按照JavaScript语言的规则编写相应代码之,浏览器可以解释并做出相应的 ...
- 关于VerilogHDL生成的锁存器
总是会遇到有写文档中提到,不要生成锁存器.问题是 一: 什么叫锁存器 二 : 为什么不要生成锁存器 三 : 如何避免生成锁存器 好,现在就这三个问题,一一做出解答 一 什么叫锁存器 锁存器(Latc ...