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 ...
随机推荐
- SQL排序
- android接入微信分享(朋友、朋友圈)、QQ分享(好友、空间)
1.申请注册你的appid 2.下载sdk QQ: http://wiki.open.qq.com/wiki/mobile/SDK%E4%B8%8B%E8%BD%BD 微信:https://open. ...
- Mac下用brew安装nginx
1. nginx nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TC ...
- 在Ubuntu 12.4 下安装 nginx, MySQL, PHP
LNMP是时下很流行的网站配置,我在配置蝉大师服务器的时候顺带把经验做个分享,蝉大师的网址是:http://www.ddashi.com/ 1.第一步, 跟新apt-get 输入: sudo apt- ...
- 【海洋女神原创】How to: Installshield做安装包时如何添加文件
我一直以为这不是一个问题,可是没想到在几个群内,对于如何向安装包添加文件不解的大有人在,今日稍暇,整理成篇,以供参考 首先我想再大声地说一遍:不要再跟我说英文看不懂了!!!!你做了程序员这一行,就得逼 ...
- MySQL 配置
MySQL 配置 1.服务启动: (1)使用 service 启动:service mysqld start (2)使用 mysqld 脚本启动:/etc/inint.d/mysqld start ( ...
- win10 用cmake 3.5.2 和 vs 2015 update1 编译 GPU版本(cuda 8.0, cudnn v5 for cuda 8.0)
win10 用cmake 3.5.2 和 vs 2015 update1 编译 GPU版本(cuda 8.0, cudnn v5 for cuda 8.0) 用vs 2015打开 编译Release ...
- git和SVN交互(待完善)
右键 git bash here 然后从SVN同步代码,git status命令,用来确认版本库状态 右键 --> TortoiseGit --> show log 打开日志 查看gi ...
- React(JSX语法)----动态UI
1.React honws how to bubble and capture events according to the spec,and events passed to your event ...
- linux命令之三
0102 文档查阅指令 cat tac nl 简单查阅,-n 可显示行 more, less less is more 查询大文件,可分页. head tail 从头尾看.-n 限制行数. taif ...