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 问题描述:回文字符串就是左右 ...
随机推荐
- BZOJ_3489_ A simple rmq problem_KDTree
BZOJ_3489_ A simple rmq problem_KDTree Description 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这 ...
- bzoj2875随机数生成器——矩阵快速幂
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2875 矩阵快速幂,把x和c分开求,最后加上即可: 为防止爆long long,要用快速乘. ...
- rsync应用实例
一. 通过ssh的方式 前面介绍的rsync 5种方式当中,第二.第三(1个冒号)就属于通过ssh的方式,这种方式其实就是让用户去登录到远程机器,然后执行rsync的任务. [root@local ...
- ubuntu下网络性能测试
iperf的主要功能 TCP 测量网络带宽 报告MSS/MTU值的大小和观测值 支持TCP窗口值通过套接字缓冲 当P线程或Win32线程可用时,支持多线程.客户端与服务端支持同时多重连接 UDP 客户 ...
- XAMPP打不开Apache服务的解决办法
XAMPP打不开Apache服务的解决办法 不用修改设置,应该是80端口被占用了,直接先IIS的网站给停了就OK
- 带emoji表情弹出层的评论框,semantic+emoji picker,java.sql.SQLException: Incorrect string value: '\xF0\x9F..'
在自己做一个项目玩时,在做评论的时候. 选中了semantic.js原型,这个在国内用的不是很多,但是在github上star数量很高,想当初我想找一个js框架是就在上面找的. semantic中文网 ...
- 检测到"_ITERATOR_DEBUG_LEVEL"的不匹配项
error: vtkCommon.lib(vtkSmartPointerBase.obj) : error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项:值“0”不 ...
- 51nod 1011 【完全背包】
完全背包的变形: 这些数字可以取多次,dp[i]代表前 i 物品组成N时的方案数. #include<iostream> #include<cstring> #include& ...
- linux命令行挂载NTFS文件系统的移动硬盘
环境 ubuntu 12.04 桌面版 由于我的ubuntu 是安装在vmware 上,如果接入移动硬盘后,它没有办法自动识别ntfs 格式的文件系统,导致mount 盘失败 从网上找到一个方法 首先 ...
- assembly x86(nasm)选择排序
有一个首地址为NUM的N字无序无符号整数数组,编制程序采用选择排序法使该数组中的数按照从小到大的次序排序输出. 选择排序: data segment message db 'This is a pro ...