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 ...
随机推荐
- 在verilog中关于inout口的设计方法
在学习IIC的时候我们知道这么设计inout inout scl : reg scl_reg , scl_en ; scl = scl_en ? scl_reg : 1'dz ; 当 ...
- 简单的java缓存实现
扫扫关注"茶爸爸"微信公众号 坚持最初的执着,从不曾有半点懈怠,为优秀而努力,为证明自己而活. 提到缓存,不得不提就是缓存算法(淘汰算法),常见算法有LRU.LFU和FIFO等算法 ...
- Internet Explorer 11(IE11)无法切换第三方输入法
Windows 8.1搭载了新的IE11版本,还发布了IE11 for Windows 7. IE11除了支持全尺寸Win设备以外,还比IE10更快速流畅,支持3D等高性能的浏览体验.全新F12开发者 ...
- Javabyte[]数组和十六进制String之间的转换Util------包含案例和代码
Java中byte用二进制表示占用8位,而我们知道16进制的每个字符需要用4位二进制位来表示(23 + 22 + 21 + 20 = 15),所以我们就可以把每个byte转换成两个相应的16进制字符, ...
- Hibernate级联操作和载入机制(二) cascade and fetch
上一篇介绍了Hibernate持久化对象时候的级联操作.本篇介绍读取时候的级联操作. 还是用上一篇的样例.一份问卷有多个问题.可是每一个问题仅仅能属于一份问卷. 我们先看測试用例: @Test pub ...
- android-改进<<仿QQ>>框架源代码
该文章主要改动于CSDN某大神的一篇文章,本人认为这篇文章的面向对象非常透彻,以下分享例如以下可学习的几点: Android应用经典主界面框架之中的一个:仿QQ (使用Fragment, 附源代码) ...
- C++ 学习笔记3,struct长度測试,struct存储时的对齐方式
之所以专门为struct的长度写一篇測试,是由于原来c++对于struct的变量, 在分配内存的时候,c++对struct有一种特殊的存储机制. 看以下的測试: 一.在Windows7 32bit , ...
- c++构造函数析构函数调用顺序
#include <iostream> using namespace std; class A { public: A () { cout<<"A 构造 " ...
- hdu 4784 Dinner Coming Soon
spfa+优先队列.刚开始只用的spfa,结果tle到死.然后听队友说要用到优先队列,想了想,对时间分层的话的确每一个结点都只进队列一次即可,因为只有大时间才能更新出小时间,然后就wa成shi了.按队 ...
- QQ与我联系
第一种 <a href=" http://sighttp.qq.com/cgi-bin/check?sigkey=ee8bdb91c04a9ae912a305a5a2461a0d8d6 ...