点击打开链接

题意:求最长回文子串所在的区间,然后第一个字符代表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. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何在初始化的时候写入参数

    最常见的是定义一个全局变量,然后跟对应的变量绑定,比如我定义了一个SINT型的变量ControlWord 数值是8,定义好之后编译一下,可以发现PLC程序中或多出来这个变量(MAIN.ControlW ...

  2. iOS 调用音乐播放以及视频播放器

    音乐播放 NSString *path = [[NSBundle mainBundle] pathForResource:@"预谋" ofType:@"mp3" ...

  3. 算法笔记_095:蓝桥杯练习 拿糖果(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 妈妈给小B买了N块糖!但是她不允许小B直接吃掉. 假设当前有M块糖,小B每次可以拿P块糖,其中P是M的一个不大于根号下M的质因数.这时,妈 ...

  4. Android4.4 SystemUI加入Dialog弹窗

    此弹窗为开机SystemUI的显示弹窗: 首先.在SystemUI的源代码文件夹加入源代码类文件,文件夹为frameworks/base/packages/SystemUI/src/com/andro ...

  5. Cannot make a static reference to the non-static method的解决方法

    报错原因:在一个类中写了一个public String getContent()方法和一个main()方法,getContent()方法中包含了getClass()方法,在main()方法中直接调用了 ...

  6. MAC OS X 10.8 操作远程SSH服务器 + 无密码输入使用SSH服务器

    怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://www.osssme.org/ 使用命令行连接连接远程SSH服务器,root为我使用的远程服务器用户名,@后为I ...

  7. C语言-常用函数处理

    1.使用fgets #define SLEN 50 char str[SLEN]; fgets(str, SLEN, stdin); i = ; while (str[i] != '\n' & ...

  8. AES + RSA + Hash 实现 C-S 安全交互

    概述 AES 由于其执行速度快,易于硬件实现,破解难度大等优势,被广泛用于数据的加密. 既然是对称加密,那如何保证秘钥的安全传输?很容易想到用 RSA 加密秘钥.由于只能用私钥解密,而私钥不需要交互双 ...

  9. 动态规划初级 入门理解 C#代码

      using System; using System.Collections.Generic; using System.Linq; using System.Text; using Micros ...

  10. python selenium --命令之文字范本匹配

    文字范本匹配 ======================================= 文字范本匹配其实可以理解为通配符.我想大家都用过windows 系统自带的搜索功能. *   星号代表一个 ...