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 问题描述:回文字符串就是左右 ...
随机推荐
- regular
regular.py import re # . # 只能匹配一个字母,而不是2个或0个 # \ # 转义 # 'abc\\.com' r'abc\.com' # 字符集[] # 匹配他所包括的任意字 ...
- Spring 事务管理高级应用难点剖析: 第 1 部分
Spring 的事务管理是被使用得最多的功能之一,虽然 Spring 事务管理已经帮助程序员将要做的事情减到了最小.但在实际开发中,如果使用不当,依然会造成数据连接泄漏等问题.本系列以实际应用中所碰到 ...
- Java操作系统硬件的方法Unsafe
通常Java代码都是运行在JVM中而不能直接访问系统硬件如进行内存分配释放等,但如果有需要跳过JVM直接用Java访问系统硬件,比如像C语言指针一样操作的话就可以调用Unsafe对象相关方法. 1.U ...
- .NET Framework4网站 无法运行,提示找不到网络名,IO错误等解决办法
.NET Framework4网站 无法运行,提示找不到网络名,IO错误等解决办法 我的这个问题解决了,原因是用的远程桌面连接的服务器, 远程桌面中部署网站的文件夹,引用的竟然是连接此服务器的用户的电 ...
- 面试题:sql数据查询
前几天参加一个面试,面试公司让做一套题,sql题不是很难,但是我第一次还是写错了,回来后,重新写了下.简单记录下吧, 1.题目: 2.测试数据 select * from student ; inse ...
- OutputDebugString()输出调试的使用
- Linux Ctrl+Z的使用方法
假设你发现前台运行的一个程序需要很长的时间,但是需要干其他的事情,你就可以用 Ctrl-Z ,终止这个程序,然后可以看到系统提示: [1]+ Stopped /root/bin/rsync.sh 然后 ...
- Yet Another Number Sequence
题意: $F_0 = 0, F_1 = 1, F_n = F_{n-1} + F_{n-2}$ 求解$\sum_{i=1}^n{ F_i i^K } \ mod \ 10^9+7$. 解法: 记$ ...
- CF 345A Mike and Frog
题目 自己歪歪的做法WA了好多发. 原题中每一秒都相当于 $x1 = f1(x1)$ $x2 = f2(x2)$ 然后这是一个定义域和值域都在[0,m-1]的函数,显而易见其会形成一个环. 而且环长不 ...
- CF-807B
B. T-Shirt Hunt time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...