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 ...
随机推荐
- 使用httpModules做一些事
httpmodules是http管道处理程序 可以重写接口进行一些在请求到达api接口前做全局处理 这是一个过滤关键词的例子 using System; using System.Collection ...
- oracle 复杂的查找用法
[第一题]: 找到员工表中工资最高的前三名,要求按如下格式输出(第一步部分):以及oracle查询结果指定分页显示的方法(第二部分). ——涉及Top-N分析问题. 一般不在子查询中使用order b ...
- intellij idea中修改代码生成的模板
File -- Settings -- Editor -- Code Style -- File and Code Templates 主要是修改了注释 /** * ${DESCRIPTION} * ...
- 点滴积累【C#】---操作文件
操作文件 写入文件效果: 写入文件代码: private void 保存ToolStripMenuItem_Click(object sender, EventArgs e) { try { File ...
- swift -变量的定义与使用
使⽤用let来声明常量,使⽤用var来声明变量. ⼀一个常量的值在编译时并不须要获取,可是你仅仅能为它赋值⼀一次.也就是说你能够⽤用常量来表⽰示这样⼀一个值:你仅仅须要决定⼀一次,可是须要使⽤用非常多 ...
- Atitit.获取主板与bios序列号获取硬件设备信息 Wmi wmic 的作用
Atitit.获取主板与bios序列号获取硬件设备信息 Wmi wmic 的作用 1 获取硬件核心基础核心基础Wmi1 2 其他资料2 3 Wmic WMI 命令行接口2 4 Atitit.获取主板 ...
- Registers
https://github.com/JesusFreke/smali/wiki/Registers Introduction In dalvik's bytecode, registers are ...
- IOS使用Charts
近期项目中要做图表功能,为了降低开发量採用的是H5+ECharts来做.这里说一下IOS中怎样使用ECharts以及遇到的问题. 网络模块化单文件引入 <!DOCTYPE html> &l ...
- 使用 xlue 实现 tips
经常遇到如下的需求 鼠标hover到目标对象一定时间后,弹出tips或者窗口; 鼠标离开目标对象一定时间后,隐藏tips或者窗口; 鼠标从目标对象移动到弹出的窗口上,这种状况下不隐藏窗口; 考虑到这种 ...
- phoneGap 3.5 eclipise 模拟器调试
最近想搞phoneGap开发,可是一看 http://www.phonegapcn.com/ phoneGap中文网 FUCK .phoneGap 还在1.0.0 里混呢.现在phoneGap 3.5 ...