hihocoder1032 最长回文子串
思路:
manacher模板。
实现:
#include <iostream>
#include <cstring>
using namespace std;
int p[];
string init(string s)
{
string res = "$#";
for (int i = ; i < s.length(); i++)
{
res += s[i]; res += '#';
}
return res;
}
int main()
{
int n;
cin >> n;
string s;
while (n--)
{
cin >> s;
memset(p, , sizeof p);
s = init(s);
int r = , id = , maxn = ;
for (int i = ; i < s.length(); i++)
{
if (i < r) p[i] = min(r - i, p[ * id - i]);
else p[i] = ;
int j = p[i];
while (s[i + j] == s[i - j]) { j++; p[i]++; }
if (i + p[i] - > r) { r = i + p[i] - ; id = i; }
maxn = max(maxn, p[i] - );
}
cout << maxn << endl;
}
return ;
}
hihocoder1032 最长回文子串的更多相关文章
- manacher hihoCoder1032 最长回文子串
居然能够做到O(n)的复杂度求最长回文.,也是给跪了. 以下这个人把manacher讲的很好,,能够看看 http://blog.csdn.net/xingyeyongheng/article/det ...
- manacherO(n)求最长回文子串 hihocoder1032
原文地址:https://segmentfault.com/a/1190000003914228 http://blog.csdn.net/synapse7/article/details/189 ...
- hihocode #1032 : 最长回文子串【manacher】模板题
题目链接:https://vjudge.net/problem/HihoCoder-1032 manacher算法详解:https://blog.csdn.net/dyx404514/article/ ...
- 最长回文子串-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 问题描述:回文字符串就是左右 ...
随机推荐
- Numpy 小结
Python 真火来学习一下,先来看一个库 NumPy.NumPy是Python语言的一个扩充程序库.支持高级大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库. 1. 读取文件 num ...
- CSS:CSS cursor 属性
ylbtech-CSS:CSS cursor 属性 1.返回顶部 1. 实例 一些不同的光标: span.crosshair {cursor:crosshair;} span.help {cursor ...
- NHibernate错误:Could not compile the mapping document的解决
用动软代码生成器的NHibernate生成模板,生成一个“XML映射模板”,老是提示Could not compile the mapping document的问题. 各种的找,就是没找到问题. 后 ...
- 开始我的技术bolg之旅
虽然做了快十年的IT但是真心觉得自己的水平很烂,IT这个行业keep learning很重要,之前每接触新东西都是随便学一下,有问题解决了就完事了,或者是再有问题临时抱佛脚,从来都没把学过或者做个的事 ...
- js正则匹配字符串
这里我第一时间想到的就是用 js 的search 和 match ,其中最常见的是match: 1. str.search(regexp):search()方法不支持全局搜索,因为会忽略正则表达式参数 ...
- UVa 12333 Revenge of Fibonacci (字典树+大数)
题意:给定一个长度小于40的序列,问你那是Fib数列的哪一项的前缀. 析:首先用大数把Fib数列的前100000-1项算出来,注意,一定不能是100000,要不然会WA的,然后每个数取前40位,不足4 ...
- flex设置默认字体为微软雅黑
必须使用英文名称 Microsoft YaHei 否则有些系统不识别
- 使用pip安装第三方插件
1. 下载Settools和pip,并安装 a. 下载地址: setuptools : https://pypi.python.org/pypi/setuptools#downloadspip: ht ...
- hihocoder #1608 : Jerry的奶酪(状压DP)
传送门 题意 分析 设dp[i][j]为在i状态下当前在第j个奶酪的最小费用 转移方程:dp[(1<<k)|i][k]=dp[i][j]+d[j][k] 预处理出每个奶酪之间的距离,加入起 ...
- ZOJ3175【公式化函数的思想】
题意: 给出f(n,m)(m<n)的定义:大于m并且小于n的能整除m的数的个数. F(n)为m从1至n的f(n,m)的和. 给出n,求F(n). 思路: 就是计算n/1 + n/2 + n/ ...