点击打开链接

题意:求最长回文子串所在的区间,然后第一个字符代表a,以后的顺推,最后输出这个区间顺推后的串

思路:Manacher轻松水过。记录下最长回文串的位置和长度即可了,然后输出时自己处理一下,大水题.......

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=200010;
char str[maxn],tmp[maxn<<1];
int len1[maxn<<1],pos;
int init(char *st){
int len=strlen(st);
tmp[0]='@';
for(int i=1;i<=2*len;i+=2){
tmp[i]='#';
tmp[i+1]=st[i/2];
}
tmp[2*len+1]='#';
tmp[2*len+2]='$';
tmp[2*len+3]=0;
return 2*len+1;
}
int Manacher(char *st,int len){
int p=0,ans=0,po=0;
for(int i=1;i<=len;i++){
if(p>i) len1[i]=min(p-i,len1[2*po-i]);
else len1[i]=1;
while(st[i-len1[i]]==st[i+len1[i]]) len1[i]++;
if(len1[i]+i>p){
p=len1[i]+i;
po=i;
}
if(len1[i]>ans){
ans=len1[i];
pos=i;
}
}
return ans-1;
}
int main(){
char ch;
while(scanf(" %c%s",&ch,str)!=-1){
init(str);
int len=init(str);
int ans=Manacher(tmp,len);
if(ans==1) printf("No solution!\n");
else{
int le,ri;
if(pos%2==0){
le=pos/2-1-ans/2;
ri=le+ans-1;
}else{
le=pos/2-ans/2;
ri=le+ans-1;
}
printf("%d %d\n",le,ri);
int t=ch-'a';
for(int i=le;i<=ri;i++){
int k=str[i]-t;
if(k>=97) printf("%c",str[i]-t);
else printf("%c",str[i]-t+26);
}
printf("\n");
}
}
return 0;
}

HDU 3294 Manacher模版题的更多相关文章

  1. 最长回文 HDU - 3068 manacher 模板题

    题意:找串的最长回文字串(连续) 题解:manacher版题 一些理解:首位加上任意两个字符是为了判断边界. 本算法主要是为了 1.省去奇偶分类讨论. 2.防止形如aaaaaaa的串使得暴力算法蜕化为 ...

  2. HDU 3294 (Manacher) Girls' research

    变形的求最大回文子串,要求输出两个端点. 我觉得把'b'定义为真正的'a'是件很无聊的事,因为这并不会影响到最大回文子串的长度和位置,只是在输出的时候设置了一些不必要的障碍. 另外要注意一下原字符串s ...

  3. Girls' research HDU - 3294(马拉车水题)

    题意: 求最长回文串 长度要大于等于2  且输出起点和终点  输出回文串字符 这个字符还是要以给出的字符为起点a 输出 解析: 分析一下s_new串就好了 #include <iostream& ...

  4. hdu 3294 manacher 求回文串

    感谢: http://blog.csdn.net/ggggiqnypgjg/article/details/6645824/ O(n)求给定字符串的以每个位置为中心的回文串长度. 中心思想:每次计算位 ...

  5. Manacher 算法(hdu 3068 && hdu 3294)

    今天打算补前晚 BC 的第二题,发现要用到能在 O(n) 时间求最大回文子串长度的 Manacher 算法,第一次听,于是便去百度了下,看了大半天,总算能看懂了其思想,至于他给出的代码模板我没能完全看 ...

  6. HDU 2222 Keywords Search(AC自动机模版题)

    Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  7. HDU 1712 ACboy needs your help (分组背包模版题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...

  8. (回文串 Manacher )Girls' research -- hdu -- 3294

    http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit:1000MS     Memory Limit:32 ...

  9. Hdu 3294 Girls' research (manacher 最长回文串)

    题目链接: Hdu 3294  Girls' research 题目描述: 给出一串字符串代表暗码,暗码字符是通过明码循环移位得到的,比如给定b,就有b == a,c == b,d == c,.... ...

随机推荐

  1. PhantomJS + Selenium webdriver 总结-元素定位

    webdriver提供了丰富的API,有多种定位策略:id,name,css选择器,xpath等,其中css选择器定位元素效率相比xpath要高些,使用id,name属性定位元素是最可靠,效率最高的一 ...

  2. 绿化和卸载 DOS 批处理

    @ECHO OFF&PUSHD %~DP0 &TITLE 绿化和选项 mode con cols= lines= color 2F Rd >NUL Md >NUL||(Ec ...

  3. VS 一键调用 SVN Blame

    在Windows上做项目开发的时候,常常需要调用SVN Blame去追溯一个文件的编辑历史,但是这个常见的需求往往需要很繁琐的步骤.首先需要打开文件所在文件夹,然后右键,在一长排上下文菜单中准确地选中 ...

  4. 算法笔记_162:算法提高 复数归一化(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 编写函数Normalize,将复数归一化,即若复数为a+bi,归一化结果为a/sqrt(a*a+b*b) + i*b/sqrt(a*a+b*b) . ...

  5. Android:singleTask + onActivityResult

    解决2个Activity互相跳转,并且栈中只保留每个Activity一个对象的存在. 在2个Activity中分别都要用到onActivityResult,所以就不能用launchMode=" ...

  6. dmesg 时间转换脚本

    https://linuxaria.com/article/how-to-make-dmesg-timestamp-human-readable perl脚本 #!/usr/bin/perl use ...

  7. O2O研究系列——O2O知识思维导图整理

    本篇文章对O2O电子商务模式的常规知识点,使用思维导图的方式整理,表达的形式是名词纲领性的方式, 不会在图中详细说明各个点. 通过这个图研究O2O模式时,可以系统的对各个业务点进行更深入的研究,避免有 ...

  8. Timer使用

    1. Timer简介 Timer是jdk中提供的一个定时器工具,使用的时候会在主线程之外起一个单独的线程执行指定的计划任务,可以指定执行一次或者反复执行多次. 通过创建Timer对象,然后调用Time ...

  9. SQL基本点—— 思维导图

  10. C# 上传文件大小限制设置

    (1)在web.comfig文件中添加一个httpRuntime主键 <httpRuntime executionTimeout="90" maxRequestLength= ...