题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3294

题意:给你一个字符和一个字符串,第一个字符表示该字符代表a,然后让你求变换后的最长回文区间并输出(这里的回文长度要大于1)

题解:直接上马拉车,然后记录一下区间

 #include<cstdio>
#include<cstring>
#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)
const int maxn = ;//字符串长度
int lb,rb;//左右区间
struct Manacher{
char str[maxn<<];
int p[maxn<<],len,mx,id,tl,ans,i;
int maxlen(char *s){
len=strlen(s),mx=,id=,tl=,str[tl++]='$',str[tl++]='#';
for(i=;i<len;i++)str[tl++]=s[i],str[tl++]='#';
for(i=,str[tl]=,ans=;i<tl;i++){
p[i]=mx>i?min(p[(id<<)-i],mx-i):;
while(str[i-p[i]]==str[i+p[i]])p[i]++;
if(i+p[i]>mx)mx=i+p[i],id=i;
if(ans<p[i])ans=p[i],lb=(i-p[i])/,rb=(i+p[i])/-;
}
return ans-;
}
}M;
char s[maxn],tt[];
int main(){
while(~scanf("%s%s",tt,s)){
for(int i=,tmp=tt[]-'a';s[i]!='\0';i++){
s[i]-=tmp;
if(s[i]<'a')s[i]=s[i]-'a'+'z'+;
}
int r=M.maxlen(s);
if(r>){
printf("%d %d\n",lb,rb);
for(int i=lb;i<=rb;i++)printf("%c",s[i]);
printf("\n");
}else printf("No solution!\n");
}
return ;
}

hdu_3294_Girls' research(Manacher)的更多相关文章

  1. Girls' research(manacher)

    Girls' research Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) ...

  2. hdu 3294 Girls' research(manacher)

    Problem Description One day, sailormoon girls are so delighted that they intend to research about pa ...

  3. hdu3294 Girls' research manacher

    One day, sailormoon girls are so delighted that they intend to research about palindromic strings. O ...

  4. HDU3294 Girls' research —— Manacher算法 输出解

    题目链接:https://vjudge.net/problem/HDU-3294 Girls' research Time Limit: 3000/1000 MS (Java/Others)    M ...

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

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

  6. 【 HDU3294 】Girls' research (Manacher)

    BUPT2017 wintertraining(15) #5F HDU - 3294 题意 给定字母x,字符串变换一下: 'x'-1 -> 'z', 'x'->'a', 'x'+1-> ...

  7. HDU----(3294)Girls' research(manacher)

    Girls' research Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)T ...

  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 (Manacher) Girls' research

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

随机推荐

  1. 6. Shell 流程控制

    1. 条件选择流程 1.1 if #!/bin/bash # if 格式 #if condition #then # command1 # command2 # ... # commandN #fi ...

  2. redis10--主从模式

    redis的主从模式(1)介绍redis存储数据是在内存中运行的,运行速度比关系型数据库要快一些.而且它具有SortSet/Hash等具有特色的数据类型,这是其它数据库无法比拟的.redis有增删改查 ...

  3. tensorflow安装相关的

    1 Install pip and Virtualenv sudo apt-get install python-pip python-dev python-virtualenv2 Create a ...

  4. Python 2.X-关于函数返回的数值类型

    在使用同一个函数,相同的参数的时候,参数在传递的过程中使用了不同的形式(有无小数点)决定了该函数返回的值的类型. # -*- coding:utf-8 -*- def return_types(one ...

  5. B-number

    B-number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3652 数位dp 这题是暑期集训的时候做的,昨天补了数位dp的记忆化搜索做法,把艾神的 ...

  6. Stack Overflow for web end

    Jquery UI tooltip on disabled button In general, disabled elements do not trigger any DOM events. Th ...

  7. KVC、KVO

    概述 由于ObjC主要基于Smalltalk进行设计,因此它有很多类似于Ruby.Python的动态特性,例如动态类型.动态加载.动态绑定等.今天我们着重介绍ObjC中的键值编码(KVC).键值监听( ...

  8. Dokan官方说明文档

    Dokan 库Copyright(c) Hiroki Asakawa http://dokan-dev.net/en 什么是Dokan库================================ ...

  9. INSTALL_FAILED_NO_MATCHING_ABIS

    在运行写好的cocos的demo时候,安装出现以下问题: 后来发现是因为自己用cygwin生成的x86的.so文件跟自己的魅族3机器CPU不适配!!! 参考:http://stackoverflow. ...

  10. heap和stack的区别

    参考<程序员面试宝典> 1.栈区(stack) 由编译器自动分配和释放,存放函数的参数值,局部变量值等.其操作方式类似于数据中的栈. 2.堆区(heap) 一般由程序员分配和释放,若程序员 ...