URAL 1297 Palindrome(Manacher)
In addition, it is reasonable to assume that the agent will be sending a very long message, so John has simply to find the longest message satisfying the mentioned property.
Input
Output
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long LL; const int MAXN = * ; char str[MAXN], s[MAXN];
int n, p[MAXN]; void manacher() {
int mx = , id;
for(int i = ; i < n; ++i) {
if(mx > i) p[i] = min(p[ * id - i], mx - i);
else p[i] = ;
while(s[i + p[i]] == s[i - p[i]]) ++p[i];
if(i + p[i] > mx) {
id = i;
mx = i + p[i];
}
}
} void print() {
int id = ;
for(int i = ; i < n; ++i)
if(p[i] > p[id]) id = i;
int l = (id - p[id] + ) / , r = l + p[id] - ;
for(int i = l; i < r; ++i) putchar(str[i]);
puts("");
} int main() {
scanf("%s", str);
s[n++] = '$', s[n++] = '#';
for(int i = ; str[i]; ++i) {
s[n++] = str[i];
s[n++] = '#';
}
s[n] = ;
manacher();
print();
}
URAL 1297 Palindrome(Manacher)的更多相关文章
- Ural 1297 Palindrome(Manacher或者后缀数组+RMQ-ST)
1297. Palindrome Time limit: 1.0 second Memory limit: 64 MB The “U.S. Robots” HQ has just received a ...
- Ural 1297 Palindrome(后缀数组+最长回文子串)
https://vjudge.net/problem/URAL-1297 题意: 求最长回文子串. 思路: 先将整个字符串反过来写在原字符串后面,中间需要用特殊字符隔开,那么只需要某两个后缀的最长公共 ...
- URAL 1297 Palindrome(后缀数组+ST表)
[题目链接] http://acm.timus.ru/problem.aspx?num=1297 [题目大意] 求最长回文子串,并输出这个串. [题解] 我们将原串倒置得到一个新的串,加一个拼接符将新 ...
- Palindrome(Manacher)
Palindrome Time Limit: 15000MS Memory Limit: 65536K Total Submissions: 6183 Accepted: 2270 Descr ...
- 【学习笔记】字符串—马拉车(Manacher)
[学习笔记]字符串-马拉车(Manacher) 一:[前言] 马拉车用于求解连续回文子串问题,效率极高. 其核心思想与 \(kmp\) 类似:继承. --引自 \(yyx\) 学姐 二:[算法原理] ...
- O(n)回文子串(Manacher)算法
O(n)回文子串(Manacher)算法 资料来源网络 参见:http://www.felix021.com/blog/read.php?2040 问题描述: 输入一个字符串,求出其中最大的回文子串. ...
- URAL 题目1297. Palindrome(后缀数组+RMQ求最长回文子串)
1297. Palindrome Time limit: 1.0 second Memory limit: 64 MB The "U.S. Robots" HQ has just ...
- ural 1297 Palindrome(Manacher模板题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 求最长回文子串. http://acm.timus.ru/problem.aspx ...
- Manacher Ural 1297 Palindrome
1297. Palindrome Time limit: 1.0 secondMemory limit: 64 MB The “U.S. Robots” HQ has just received a ...
随机推荐
- js的单例
对于 JS 来说,巨大的灵活性使得其可以有多种方式实现单例模式,使用闭包方式来模拟私有数据,按照其思路可得: var single = (function(){ var unique; functi ...
- form表单的一个页面多个上传按钮实例
/* * 图片上传 */ @RequestMapping("/uploadFile") @ResponseBody public String uploadFile(@Reques ...
- nginx的docker化部署
nginx的docker化有一个隐藏的坑,就是其默认的配置目录(/etc/nginx)需要先从容器中拷贝出来. 拉取镜像 docker pull nginx 启动容器 docker run -d -- ...
- 入口文件 index.php 隐藏
入口文件 index.php 隐藏 在PHP的web项目中,问了隐藏项目的开发语言,我们首先会选择把项目的入口文件index.php(如果做了特殊配置,特殊处理)在URL中隐藏掉. 当然部署中还需要隐 ...
- 解决gradle下载慢的问题(转)
问题一:新建项目下载gradle慢的问题 解决方法: 打开用户主目录 linux平台/home/用户名/.gradle windows平台c:\Users\用户名\.gradle macos平台/Us ...
- fake_useragent 封装好user-agent的模块
from fake_useragent import UserAgent useragent = UserAgent()print(useragent.random)
- java中有关Volatile的几个小题
1.java中能创建volatile数组吗? 能,java中可以创建volatile数组,不过只是一个指向数组的引用,而不是整个数组,如果改变引用指向的数组,将会受到volatile的保护,但是如果多 ...
- (转载)PHP环境搭建-记录
PHP环境搭建-记录 转于 http://jingyan.baidu.com/article/fcb5aff797ec41edaa4a71c4.html php5.5 做了大量的更新,在与apac ...
- Go语言的数据类型
1 概述 Go语言作为类C语言,支持常规的基础数据类型的的同时,支持常用的高级数据类型.他们是: 整数,int,uint,int8,uint8,int16,uint16,int32,uint32,in ...
- js闭包的理解-目前网上分析的最透彻文章
js的闭包对于大家实际上并不陌生,但是真正敢说自己完全理解的人并不多.笔者在网上看到分析闭包的文章非常多,篇幅用的非常多,但是实际上分析的并不到位,或者根本就是不正确的.我有时候都在想,写这些文章的人 ...