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 问题描述:回文字符串就是左右 ...
随机推荐
- Java连接redis操作数据
选择2.9.0 jar 版本下载: jedis-2.9.0.jar package com.hao.redis; import org.junit.Before;import org.junit.Te ...
- QQ登陆功能的实现2
QQ登陆功能的实现2 由于看到园子里有朋友说需要讲解和剖析实现的步骤,前面的QQ登陆实现只有代码,所以这篇补上 1. 分析 1). 当运行QQ.exe后会出现qq登陆界面的窗体 2). 我们用spy ...
- python虚拟环境管理包virtualenvwrapper
1.打开cmd 2.安装virtualenvwrapper pip install virtualenvwrapper-win 3.配置虚拟环境的位置 新建系统变量默认在c盘 4.新建虚拟环境 mkv ...
- synergy的配置使用
1.http://blog.csdn.net/qq_16618179/article/details/54094636 2.两个版本要一致 3.synergy fail to connect sec ...
- 3.2-3.3 Hive中常见的数据压缩
一.数据压缩 1. 数据压缩 数据量小 *本地磁盘,IO *减少网络IO Hadoop作业通常是IO绑定的; 压缩减少了跨网络传输的数据的大小; 通过简单地启用压缩,可以提高总体作业性能; 要压缩的数 ...
- 转载 关于启用HTTPS的一些经验分享
本文转载自 https://imququ.com/post/sth-about-switch-to-https.html 随着国内网络环境的持续恶化,各种篡改和劫持层出不穷,越来越多的网站选择了全站 ...
- E20190303-hm
invoke vt. 乞灵,祈求; 提出或授引…以支持或证明; 召鬼; 借助;
- lightoj1006【记忆化搜索(我是这么叫)】
搜索的时候记录一下,注意要long long: #include<cstdio> #include<queue> #include<map> #include< ...
- 换装demo时美术遇到的问题详解
1.武器替换:MAX的东西进Unity,根骨骼X轴会有270度的旋转. 解决方法:由程序强制武器进入Unity后的旋转角度. 2.蒙皮问题:face和hair等脖子以上部位蒙皮的时候,导入Unity后 ...
- 洛谷P3265 [JLOI2015]装备购买(线性基+高斯消元)
传送门 不知道线性基是什么东西的可以看看蒟蒻的总结 不难看出题目讲的就是线性基 这种最小化权值的问题一般都是贪心的,就是按价值从低到高考虑每一个是否能选 据说贪心的证明得用拟阵我不会 据说这题是实数意 ...