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 ...
随机推荐
- MouseOver/MouseOut vs MouseEnter/MouseLeave
参考 http://www.oschina.net/question/234345_45280 这是jQuery提供的函数 要注意MouseOut 和 MouseLeave的区别 比如对元素A绑定Mo ...
- BaseAdapter导致notifyDataSetChanged()无效的四个原因及处理方法
前一段时间在做一个项目的时候遇到了一个关于BaseAdapter的notifyDataSetChanged()方法无效问题,当时在网上搜了一个解决方法,今天又遇到了一个类似的问题,我在这里做个记录,防 ...
- Protel对话窗字体显示不完全问题解决办法(PCB)
点击protel99左上角的大箭头,点击preferences ,在对话框中把use client system fonts for all dialogs 复选框去掉,就可以了.
- CentOS 6.5(64bit)安装GCC4.8.2+Qt5.2.1(替换GCC的链接库)
截至目前,Qt的最新版本为5.2.1,CentOS的版本为6.5,GCC的版本为4.8.2,经过一番尝试,终于将Qt开发环境安装到了CentOS(64 bit)中,整个过程中有几个需要注意的地方,在这 ...
- DataReader的例子
前: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataReader对 ...
- Spreadsheets
很水的一道题,提醒自己要认真,做的头都快晕了.考虑26的特殊情况. D - Spreadsheets Time Limit:10000MS Memory Limit:65536KB 6 ...
- SICP 习题 (2.7) 解题总结 : 定义区间数据结构
SICP 习题 2.7 開始属于扩展练习,能够考虑不做,对后面的学习没什么影响.只是,假设上面的使用过程表示序对,还有丘奇计数你都能够理解的话,完毕这些扩展练习事实上没什么问题. 习题2.7是要求我们 ...
- Android 使用动态载入框架DL进行插件化开发
如有转载,请声明出处: 时之沙: http://blog.csdn.net/t12x3456 (来自时之沙的csdn博客) 概述: 随着应用的不断迭代.应用的体积不断增大,项目越来越臃肿,冗余添 ...
- 西门子PLC学习笔记二-(工作记录)
今天师傅给讲了讲做自己主动化控制的总体的思路,特进行一下记录,做个备忘. 1.需求分析 本次的项目是对楼宇循环供水的控制,整个项目须要完毕压力.压差.温度等的获取及显示.同一时候完毕电机的控制. 2. ...
- javascript得知 - js的Date对象函数
js的Date功能很强大.通常使用. 首先获得当前的日期: var CurDate = new Date(); var Year = CurDate.getFullYear(); //年份(四位 例: ...