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 问题描述:回文字符串就是左右 ...
随机推荐
- [HAOI 2010] 计数
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2425 [算法] 类似与数位动态规划的思想 , 用组合数学进行简单推导即可 时间复杂度 ...
- Python使用multiprocessing实现一个最简单的分布式作业调度系统
Python使用multiprocessing实现一个最简单的分布式作业调度系统介绍Python的multiprocessing模块不但支持多进程,其中managers子模块还支持把多进程分布到多台机 ...
- Mysql数据库--语句整理/提升/进阶/高级使用技巧
一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...
- nagios对windows流量的检测
windows下用于和 nagios 整合监控的方式主要有三种:nsclient++ .nrpe_nt.SNMP.三者各自的特点主要如下: 1.nsclient++比较成熟稳定,文档也丰富,内置很多了 ...
- SimpliciTI Sample Applications
Sample Applications 介绍了4个简单的示例应用程序来演示SimpliciTI的各种特性和功能. Simple Peer-To-Peer :two linked End-Devices ...
- javamail - 发件、收件(SSL连接)
需要的包:mail.jar jsse.jar(说明:jsse.jar是jre自带的,如果jdk1.5及以下需要Java Activation Framework框架的activation.jar) ...
- jQuery.validator.addMethod方法的使用
该方法有三个api接口参数,name,method,messages addMethod(name,method,message)方法 参数 name 是添加的方法的名字. 参数 method 是一个 ...
- .Net框架中的CLR,CTS,ClS的解释
CLR的全称(Common Language Runtime) 公共语言运行时 可以把它理解为包含运行.Net程序的引擎 和 一堆符合公用语言基础(CLI)的类库的集合,他是一个规范的实现,我们开发的 ...
- D - Bear and Finding Criminals
Description There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long ro ...
- python如何实现相对导入
如果python中导入的package或module不在环境变量PATH中,可以使用sys.path将要导入的package或module加入到PATH环境变量中,之后便能使用相对导入方法. 拿hom ...