题目大意:有多组数据,每组数据给出一个字符和一个字符串。该字符将变成’a‘,表示字符串中的所有该字符将变成’a‘,同时其他字符也将做相同的偏移。具体来说,如果该字符为’b‘,表示字符串中的’b‘都将变成a,偏移量为-1。此时字符串的其他字符都要做这个偏移,比如c将变成‘b’,'d'将变成‘c’……,而‘a’将变成‘z’。

现在给出许多这样的数据,要求出转换过后的最长的回文串。

分析:求回文串用manacher算法。因为manacher中会插入字符,从而改变原来的字符的位置。所以输出位置时要小心处理。一开始搞错了,位置多减了一个1,却过了样例和自己出的几个小数据。一定要多测试一些数据才行。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 400005
char s1[MAXN],s2[MAXN];
char str[];
int p[MAXN],maxid,ans=,pos;
void manacher(char *s)
{
int len=strlen(s);
p[]=,maxid=;
for(int i=;i<len;++i)
{
if(maxid+p[maxid]>i)
p[i]=min(p[*maxid-i],maxid+p[maxid]-i);
else p[i]=;
for(;s[i+p[i]]==s[i-p[i]];p[i]++);
if(p[i]+i>p[maxid]+maxid)maxid=i;
}
}
int main()
{
while(scanf("%s %s",str,s1)!=-)
{
int len=strlen(s1);
ans=;
pos=;
memset(s2,,sizeof s2);
s2[]='*';
s2[]='#';
for(int i=,j=;i<len;i++)
{
s2[j++]=s1[i];
s2[j++]='#';
}
manacher(s2);
len=strlen(s2);
for(int i=;i<len;i++)
{
if(p[i]>ans)
{ans=p[i];
pos=i;
}
}
if(ans<=)
{printf("No solution!\n");
continue;
}
pos-=(ans-);
pos=(pos-)/; printf("%d %d\n",pos,pos+ans-);
for(int i=pos;i<pos+ans-;i++)
{
s1[i]-=(str[]-'a');
if(s1[i]<'a')
s1[i]+=;
printf("%c",s1[i]);
}
printf("\n");
}
}

hdu3294 girl‘s research的更多相关文章

  1. 【 HDU3294 】Girls' research (Manacher)

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

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

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

  3. hdu3294 Girls' research manacher

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

  4. kuangbin专题十六 KMP&&扩展KMP HDU3294 Girls' research

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

  5. HDU3294 Girls' research

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  6. hihoCoder 1427 : What a Simple Research(大㵘研究)

    hihoCoder #1427 : What a Simple Research(大㵘研究) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...

  7. [转载]Three Trending Computer Vision Research Areas, 从CVPR看接下来几年的CV的发展趋势

    As I walked through the large poster-filled hall at CVPR 2013, I asked myself, “Quo vadis Computer V ...

  8. (转) Deep Learning Research Review Week 2: Reinforcement Learning

      Deep Learning Research Review Week 2: Reinforcement Learning 转载自: https://adeshpande3.github.io/ad ...

  9. MLA Handbook for Writers of Research Papers笔记

    MLA Handbook for Writers of Research Papers.7th ed.New York:MLA,2009.print.还有一本,留待阅读MLA Style Manual ...

随机推荐

  1. jquery jqPlot API 中文使用教程

    jqPlot是一个灰常强大的图表工具,曲线,柱状,饼图,应该有尽有,更要命的是,调用方便~~ 官网:http://www.jqplot.com/ 这里贡献上中文教程,基本上所有的api都很齐全,供有需 ...

  2. oracle数据库卸载(需要完全卸载oracl才能重装)

    1. 开始->设置->控制面板->管理工具->服务 停止所有Oracle服务. 2. 开始->程序->Oracle - OraHome81->Oracle I ...

  3. 深入理解Javascript中this, prototype, constructor

    在Javascript面向对象编程中经常需要使用到this,prototype和constructor这3个关键字. 1.首先介绍一下this的使用:this表示当前对象;如果在全局中使用this,则 ...

  4. SQLiteDeveloper破解

    Sqlite 管理工具 SQLiteDeveloper及破解 功能特点 表结构设计,数据维护,ddl生成,加密数据库支持,sqlite2,3支持 唯一缺憾,收费,有试用期 下载地址: http://w ...

  5. .net 如何引用迅雷组件

    本文记录两个部分,本人自己引用迅雷组件的经历和引用迅雷组件相关原理 the first: 添加引用 -> COM -> ThunderAgent 1.0 Type Library(前提是已 ...

  6. NLP中word2vec的CBOW模型和Skip-Gram模型

    参考:tensorflow_manual_cn.pdf     Page83 例子(数据集): the quick brown fox jumped over the lazy dog. (1)CBO ...

  7. ipython notebook 显示图

    import random import matplotlib from pylab import * %pylab inline list = [random.random() for i in r ...

  8. 【转】Web Service单元测试工具实例介绍之SoapUI

    转自:http://blog.csdn.net/oracle_microsoft/article/details/5689585 SoapUI 是当前比较简单实用的开源Web Service 测试工具 ...

  9. tabelView右滑选择进行删除

    如何使用UITableViewRowAction实现右滑选择呢? 1.在iOS8以前,我们实现tableview中滑动显示删除,置顶,更多等等的按钮时,都需要自己去实现,在iOS8中系统已经写好了,只 ...

  10. uva1635

    /* 哑元 组合数的递推整除判断_________________________________________________________________________________ #i ...