题目连接: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. 转发一个javascript的编码规范

    google出品:http://chajn.org/jsguide/javascriptguide.html

  2. python ast

    import ast print ast.literal_eval('[1, 2, 3]')print eval("2 + 3 * len('hello')") == 17prin ...

  3. NYIST OJ 题目38 布线问题

    最小生成树水题,先按最小生成树做,答案最后加上最小的从第i号楼接线到外界供电设施所需要的费用即可. #include<cstdio> #include<cstring> #in ...

  4. html5权威指南:标记文字、组织内容、文档分节

    HTML5新增及删除标签:http://www.cnblogs.com/starof/archive/2015/06/23/4581850.html 第八章:标记文字                 ...

  5. php websocket聊天室

    要理解socket就要先理解http和tcp的区别,简单说就是一个是短链,一个是长链,一个是去服务器拉数据,一个是服务器可以主动推数据. 而socket就是应用层与TCP/IP协议族通信的中间软件抽象 ...

  6. Linux入门(三)搭建服务器linux运行环境LAMP/LNMP

    本文内容主要根据慕课网教学视频整理,原链接http://www.imooc.com/learn/170 我用的linux系统是ubuntu 12.04 LTS  虚拟机是VMware Workstat ...

  7. POJ 2234 Matches Game(取火柴博弈1)

    传送门 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  8. 解决Firefox访问12306"连接不受信任"的问题

    用Firefox访问12306.cn, 总是提示"This Connection is Untrusted", 曾经有个"Add Exception" 按钮, ...

  9. Python & virtualenv使用说明

    virtualenv是virtual environment的缩写,可以创建独立的Python环境,用起来比较干净:   安装(已安装pip 或者 easy_install): 如果使用pip: pi ...

  10. Web调用安卓,苹果手机摄像头,本地图片和文件

    由于要给一个客户做一个记账WAP,里面有调用手机拍照功能,这里记录一下,以供需要的朋友,下面是完整的一个HTML页面内容,放在服务器上然后浏览就可以了,只支持Chrome和Safari核的浏览器,我测 ...