hdu3294 girl‘s research
题目大意:有多组数据,每组数据给出一个字符和一个字符串。该字符将变成’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的更多相关文章
- 【 HDU3294 】Girls' research (Manacher)
BUPT2017 wintertraining(15) #5F HDU - 3294 题意 给定字母x,字符串变换一下: 'x'-1 -> 'z', 'x'->'a', 'x'+1-> ...
- HDU3294 Girls' research —— Manacher算法 输出解
题目链接:https://vjudge.net/problem/HDU-3294 Girls' research Time Limit: 3000/1000 MS (Java/Others) M ...
- hdu3294 Girls' research manacher
One day, sailormoon girls are so delighted that they intend to research about palindromic strings. O ...
- kuangbin专题十六 KMP&&扩展KMP HDU3294 Girls' research
One day, sailormoon girls are so delighted that they intend to research about palindromic strings. O ...
- HDU3294 Girls' research
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- hihoCoder 1427 : What a Simple Research(大㵘研究)
hihoCoder #1427 : What a Simple Research(大㵘研究) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...
- [转载]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 ...
- (转) Deep Learning Research Review Week 2: Reinforcement Learning
Deep Learning Research Review Week 2: Reinforcement Learning 转载自: https://adeshpande3.github.io/ad ...
- MLA Handbook for Writers of Research Papers笔记
MLA Handbook for Writers of Research Papers.7th ed.New York:MLA,2009.print.还有一本,留待阅读MLA Style Manual ...
随机推荐
- [Java Basics3] XML, Unit testing
What's the difference between DOM and SAX? DOM creates tree-like representation of the XML document ...
- java 对象 :创建
灵感来自effective java 关于对象,是java的核心,如何有效的创建其实是一个值得关注的地方. 1.静态工厂:这是一个值得关注的,并且应该时刻考虑的方法. 优点:1.他是有名字的,这个是如 ...
- Android中proc/meminfo的详解(原)
今天在写到获取手机可用内存空间的总大小的时候,通过下面的方法去获取的时候,发现该方法最低支持的版本是16,这显然是不可取的. public static long getTotalSpace(Cont ...
- ubuntu 14.04安装右键打开终端功能
命令行运行,安装完成后需重启: sudo apt-get install nautilus-open-terminal
- RadioButtonList的使用
前台绑定: <asp:RadioButtonList ID="hlBatchYuJi" runat="server" RepeatColumns=&quo ...
- Flask 的扩展
1. Flask-Script,为Flask程序提供了一个命令行解析器: (venv) $ pip install flask-script 2. Bootstrap(http://getbootst ...
- c语言数据结构之 快速排序
编译器:VS2013 #include "stdafx.h"#include<stdlib.h> //函数声明 void QuickSort(int a[],int n ...
- POJ 1014 Dividing
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 66032 Accepted: 17182 Descriptio ...
- Java.lang.String 乱码反编译
这个有个前提就是要知道错误的编码和应该转换的正确的编码 比如 gbk = >utf-8 可以 System.out.println("具体的乱码".getBytes(&quo ...
- Enum.GetHashCode()的问题
先说一下,正常如果代码可以定义成枚举,我是比较倾向于定义成枚举的,类似这样: public enum Gender { /// <summary> /// 男 /// </summa ...