ural1297. Palindrome
1297. Palindrome
Memory limit: 64 MB
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
Sample
input | output |
---|---|
ThesampletextthatcouldbereadedthesameinbothordersArozaupalanalapuazorA |
ArozaupalanalapuazorA |
Problem Source: IX Open Collegiate Programming Contest of the High School Pupils (13.03.2004)
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int N=1e6+;
char s[N],S[N<<];
int l,p[N];
void manacher(){
int mx=-,id=,ans=,pos=;
for(int i=;i<l;i++){
if(id+mx>i) p[i]=min(p[id*-i],id+mx-i);
while(i-p[i]->=&&i+p[i]+<=l&&S[i-p[i]-]==S[i+p[i]+]) p[i]++;
if(id+mx<i+p[i]) id=i,mx=p[i];
if(ans<p[i]) ans=p[i],pos=i;
}
bool f=;
if(S[pos]!='#') pos++;else f=;
pos/=;ans/=;
s[pos+ans+]=;pos-=ans;
if(f) pos++;
puts(s+pos); }
int main(){
while(scanf("%s",s+)==){
int len=strlen(s+);
l=-;
for(int i=;i<=len;i++) S[++l]='#',S[++l]=s[i];
S[++l]='#';
manacher();
}
return ;
}
/*
in:
oUtkzqGlUgWNznyqfXYTPFLgaQrHORMTuKJZtFsmAcWGgMJvtSrRIjElhsCiSGKCFFrHpxdcmQnEZpYsujebwDWhwMbyuDWWHWBJJQlxeCVgokrOuTGbRfVmlionoQiQPGkvMmfNfhohxQvseSoUZOKkXTVxiElofJtujfZPVBWfKBrCrmEyznOUorfwpsYirVQdKwKKWOHoYLDuqqczmqPHBBVpaqldmhmiEdgeqaspGyFbYqdsARnqzcjmjgtndaTpfeFfvVVvooCyOdnelFzDqjzcqRKckRXTnQCWvPRmpnnrRfveyGpWqxcLqEOmotDisqghJtwcouyanxyRAdUvqdLlIvElpleVqEcxBvuYnhTGsoZIfdTdnuCVWOjbfUFtZbaXCIvNaJMsVfhAZfwbHQnmXosLByYxgpCPisNtEuEQsZRZpCTRobllnIYFUKpovYAxhnAUlAam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ZacaFtFsUdUcTAliSiBinQZRiaQkbUSnoJwAzJaKyHcUWtmpCfMAIejjlursXVyTOGraEjiVKTqmpoIRPmtWQlqYbRomfNVFgfSGSXkpqHeqOUlHOunGUpDuYTEZIOXjIrJMFQKjZMZhUQHZUWpRuCvYouLNsqanKdeRJJRaMBMEDKznPSYMsVATAXPkreBYPHVWGKZwlQxHCiXmnKYVnusYdDhHAlFuKKhKyYANJYIcukqHVqzCfiOdrgklcVqjHUFhQnQqnGJgqnDutvECxkfUkqwFzIoHUJvVibbbZydwXaYlGQLweQZNvuxnJrfiKEDlEdVfbyfGgbtDVezgjSMLjJmJRFRWYKcBHQpPNihWhBLZurbxhXdNmVwzqyGsoTbucCVxkTkBBviDRJlZVfUnygxmHWbMdDOFHlNZbWfGDJItLDDOCZGkoTprZkAtJgikTHWgEziBNxdspLYliEsOdINixFXBgyNZuSlfwfnIvtFBvYDrRRojBwOiYhjIvHhBquUWSsaScmikxKMsAZsweijSQivoJlUMzyOlwQQIELhdvERYwxxKPoTayBfDxxsCPmWrYXgcfuUNeZvFJoKSlEDQidZdBKZnOGAJaFQwbgKPfCEVBcfSmTgucgKJnkYbbFoXDojHSiUHdkzinrygmyWxtKhlxKvCSwkVApomeausoMTbdmioiFbEgAEYimAzLVLWhITtKEuiIcZEOfGvjOYhjBXlzuKixHyULLkEiWrZuPAjnnmgTwynuFtuydaYhmtBtXuebpBeCKPNibWzycLFiEdZdQkApqFNHlXUkSWkxdLxRBnzTcxXYZzmjjRA out:
vVVv
*/
ural1297. Palindrome的更多相关文章
- Ural1297 Palindrome(后缀数组)
[题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=12406 [题意] 求最长回文子串. [思路] 将字符串 ...
- 【ural1297】 Palindrome
http://acm.timus.ru/problem.aspx?space=1&num=1297 (题目链接) 题意 求最长回文子串 Solution 后缀数组论文题 穷举每一位,然后计算以 ...
- 1297. Palindrome ural1297(后缀数组)
1297. Palindrome Time limit: 1.0 secondMemory limit: 64 MB The “U.S. Robots” HQ has just received a ...
- URAL1297:Palindrome——题解
http://acm.timus.ru/problem.aspx?space=1&num=1297 https://vjudge.net/problem/URAL-1297 给定一个字符串,求 ...
- 【Ural1297】Palindrome(后缀数组)
题意:求一个字符串的最长回文子串 n<=1000 思路:这是一道论文题 需要注意的细节: 1.奇偶分类 2.中间的分割符与最后的附加字母都是最小值,但两者不能相同,否则height可能会出现问题 ...
- 回文串---Palindrome
POJ 3974 Description Andy the smart computer science student was attending an algorithms class whe ...
- URAL - 1297 Palindrome —— 后缀数组 最长回文子串
题目链接:https://vjudge.net/problem/URAL-1297 1297. Palindrome Time limit: 1.0 secondMemory limit: 64 MB ...
- PALIN - The Next Palindrome 对称的数
A positive integer is called a palindrome if its representation in the decimal system is the same wh ...
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
随机推荐
- (八)Oracle学习笔记—— 触发器
1. 触发器简介 触发器在数据库里以独立的对象存储,类似于过程(procedure)和函数(function),都有声明,执行和异常处理过程的PL/SQL块.它与存储过程和函数不同的是,存储过程与函数 ...
- Python 使用 UTF-8 编码(转)
Python 使用 UTF-8 编码(转) 原文出处:http://blog.chenlb.com/2010/01/python-use-utf-8.html 一般我喜欢用 utf-8 编码,在 py ...
- bootstrap 学习笔记 轮播(Carousel)插件
Bootstrap轮播(carousel)插件是一种灵活的响应式的向站点添加滑块的方式.除些之外,内容也是足够灵活的,可以是图像,内嵌框架,视频或者其他您想要旋转的任何类型的内容. 示例: 下面是不念 ...
- 点滴记录:input的value不能放值
以前我写登录框交互的时候,总是在focus和blur时,把input的value值为空或显示,也一直认为对的没有争议.可是,今天,后台同学告诉我这个不好使了?!我一时没听明白,后来他亲自演示后,我才 ...
- Docker运行报Cannot connect to the Docker daemon错误
核心问题所在:权限不足 操作docker命令提示:Cannot connect to the Docker daemon 请切换管理员权限,root权限,root安装的一般的用户访问会存在此问题.
- C#指南,重温基础,展望远方!(4)表达式
表达式是在操作数和运算符的基础之上构造而成. 表达式的运算符指明了向操作数应用的运算. 运算符的示例包括 +.-.*./ 和 new. 操作数的示例包括文本.字段.局部变量和表达式. 如果表达式包含多 ...
- 接收广播BroadcastReceiver
Broadcast Receiver用于接收并处理广播通知(broadcast announcements).多数的广播是系统发起的,如地域变换.电量不足.来电来信等.程序也可以播放一个广播.程序可以 ...
- POJ-1318(list.sort()输出不为字典序,map才是按字典序排列)
#include<iostream> #include<string> #include<list> #include<map> #include< ...
- atitit.验证码识别step2------剪贴板ClipBoard copy image图像 attilax总结
atitit.验证码识别step2------剪贴板ClipBoard copy image图像 attilax总结 剪贴板(ClipBoard)是内存中的一块区域,是Windows内置的一个非常有用 ...
- Git-查看远程分支、本地分支、创建分支
1.查看本地分支 $ git branch * br-2.1.2.2 master 2.查看远程分支 $ git branch -r origin/HEAD -> origin/master o ...