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 ...
随机推荐
- 关于git 操作
一. Git 命令初识 在正式介绍Git命令之前,先介绍一下Git 的基本命令和操作,对Git命令有一个总体的认识 示例:从Git 版本库的初始化,通常有两种方式: 1)git clone:这是一种较 ...
- ASP.NET空网页生成默认代码注释
当在Visual Studio下生成ASP.NET空网页时,默认生成代码: <%@ Page Language="C#" AutoEventWireup="true ...
- oracle xmltype导入并解析Excel数据 (一)创建表与序
表说明: T_EXCEL_IMPORT_DATASRC: Excel数据存储表,(使用了xmltype存储Excel数据) 部分字段说明: BUSINESSTYPE: Excel模板类型,一个Exce ...
- Razor视图添加命名空间
在.cshtml文件添加@using MyNamespace,只是在页面添加引用这样编译不通过,还需要在view文件夹的web.config添加引用,找到<namespaces>添加< ...
- 使用ActionBar Tab
使用ActionBar Tab(地址) 本文实现将页面分为多个选项卡,并在每一个选项卡中显示一个ListView. 创建新Layout - ActionbarTab.axml, 并向页面中添加Fram ...
- 百川sdk----自己的WebViewClient不被执行
我在百川sdk的旺旺群中,追问这个问题N多次,一直没有人答复,哎,凡事都要靠自己..... 1.先查看下百川sdk中,是怎么处理咱们传递过去的 WebViewClient public class l ...
- iOS--基础控件总结一
UIWindow窗口 UIView视图 UIButten按钮 UILabel文本显示 UITextField输入框 UI TextView多行输入框 UISwitch开关 UISegmentedCon ...
- JSTL的fn函数
JSTL使用表达式来简化页面的代码,这对一些标准的方法,例如bean的getter/setter方法,请求参数或者context以及session中的数据的访问非常方便,但是我们在实际应用中经常需要在 ...
- jquery 无缝滚动 jquery.kxbdmarquee
DEMO http://code.ciaoca.com/jquery/kxbdmarquee/demo/ 官网 http://code.ciaoca.com/jquery/kxbdmarquee/ D ...
- python基础(1)
一.应用 python应用:数据分析.组件集成.网络服务.图像处理.数值计算和科学计算. 使用python的企业:YouTube.dropbox.BT.Quora.豆瓣.知乎.google.Yahoo ...