Girls' research

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 537    Accepted Submission(s): 199

Problem Description
One day, sailormoon girls are so delighted that they intend to research about palindromic strings. Operation contains two steps:
First
step: girls will write a long string (only contains lower case) on the
paper. For example, "abcde", but 'a' inside is not the real 'a', that
means if we define the 'b' is the real 'a', then we can infer that 'c'
is the real 'b', 'd' is the real 'c' ……, 'a' is the real 'z'. According
to this, string "abcde" changes to "bcdef".
Second step: girls will
find out the longest palindromic string in the given string, the length
of palindromic string must be equal or more than 2.
 
Input
Input contains multiple cases.
Each
case contains two parts, a character and a string, they are separated
by one space, the character representing the real 'a' is and the length
of the string will not exceed 200000.All input must be lowercase.
If the length of string is len, it is marked from 0 to len-1.
 
Output
Please execute the operation following the two steps.
If
you find one, output the start position and end position of palindromic
string in a line, next line output the real palindromic string, or
output "No solution!".
If there are several answers available, please choose the string which first appears.
 
Sample Input
b babd
 
a abcd
 
Sample Output
0 2
aza
No solution!
 
Author
wangjing1111
 
Source
 
代码:题目意思:
给定一个字符,以该字符作为'a'字符,举列子: c abac , c=a; b=z ,a=y;
 然后找出他的最长回文子串,标出他的起始位置和最终位置...然后输出它的回文串(变换后的)
做法:  先用manacher求出它的最长回文串,算法起始点,可以考虑另外开一个数组,来存储原始字串....然后依据起始和结尾点来输出即可
,采用manacher算法处理回文子串
 
 
代码:
 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define maxn 400050
char str[maxn];
int rad[maxn];
int Min(int a,int b){
return a<b?a:b;
}
void init(int len,char s[]){
memset(rad,,sizeof(int)*(*len+));
s[len*+]='\0';
int i,j=;
for(i=len*+;i>;i--){
if(i&) s[i]='#';
else{ s[i]=s[len-j];
j++;
}
}
s[]='$'; //防止溢出
}
int manacher(int len){
int id,i,ans=;
for(i=;i<len*+;i++){
if(id+rad[id]>i) rad[i]=Min(rad[id*-i],id+rad[id]-i);
while(str[i-rad[i]]==str[i+rad[i]]) rad[i]++;
if(i+rad[i]>id+rad[id]) id=i;
if(ans<rad[i])ans=rad[i];
}
return ans;
}
int main(){
char sav[];
int len,i;
//system("call test.in");
//freopen("test.in","r",stdin);
// fclose(stdin);
while(scanf("%s%s",sav,str)!=EOF){
len=strlen(str);
init(len,str);
int ans=manacher(len);
if(ans<=)puts("No solution!");
else{
for(i=;i<len*+;i++)
if(ans==rad[i]) break;
int st,en;
st=(i-ans)/;
en=st+ans-;
printf("%d %d\n",st,en);
for(int j=(st+)*;j<(st+ans)*;j+=){
if(str[j]-(sav[]-'a')<'a')
printf("%c",str[j]+('z'-sav[]+));
else
printf("%c",str[j]-(sav[]-'a'));
}
puts("");
}
}
return ;
}

HDU----(3294)Girls' research(manacher)的更多相关文章

  1. (回文串 Manacher )Girls' research -- hdu -- 3294

    http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit:1000MS     Memory Limit:32 ...

  2. HDU 3294 Girls' research(manachar模板题)

    Girls' researchTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...

  3. 吉哥系列故事——完美队形II---hdu4513(最长回文子串manacher)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4513 题意比最长回文串就多了一个前面的人要比后面的人低这个条件,所以在p[i]++的时候判断一下s[i ...

  4. hdu-3068(最长回文子串-manacher)

    题意:求一个字符串#include<iostream>#include<algorithm>#include<cstring>using namespace std ...

  5. Hdu 3294 Girls' research (manacher 最长回文串)

    题目链接: Hdu 3294  Girls' research 题目描述: 给出一串字符串代表暗码,暗码字符是通过明码循环移位得到的,比如给定b,就有b == a,c == b,d == c,.... ...

  6. HDU 3948 The Number of Palindromes(Manacher+后缀数组)

    题意 求一个字符串中本质不同的回文子串的个数. $ 1\leq |string| \leq 100000$ 思路 好像是回文自动机的裸题,但是可以用 \(\text{Manacher}\) (马拉车) ...

  7. HDU - 3068 最长回文(manacher算法)

    题意:给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度. 分析: manacher算法: 1.将字符串中每个字符的两边都插入一个特殊字符.(此操作的目的是,将字符串 ...

  8. 【HDU 4352】 XHXJ's LIS (数位DP+状态压缩+LIS)

    XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. HDU 3416 Marriage Match IV (最短路径,网络流,最大流)

    HDU 3416 Marriage Match IV (最短路径,网络流,最大流) Description Do not sincere non-interference. Like that sho ...

随机推荐

  1. CentOs6.5中安装和配置vsftp简明教程

    一.vsftp安装篇 # 查看是否已经安装了vsftp: rpm -qa|grep vsftpd # 安装vsftpd(需要root权限)yum -y install vsftpd# 启动vsftpd ...

  2. 在Spring中使用脚本

    Spring支持3中不同的脚本语言(看来支持地还挺多的嘛):JRuby.Groovy和BeanShell. 这三个都是java社区的脚本语言(反正到目前为止我一个都没用过,可见我有多挫). JRuby ...

  3. 清除SVN获取文件的所有.svn文件夹

    Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\清除SVN信息] @=&qu ...

  4. ABAP WRITE、WRITE TO、FORMAT语句

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. 【面向打野编程】——KMP算法入门

    一.问题 咱们先不管什么KMP,来看看怎么匹配两个字符串. 问题:给定两个字符串,求第二个字符串是否包含于第一个字符串中. 为了具体化,我们以 ABCAXABCABCABX 与 ABCABCABX为例 ...

  6. bzoj 1202: [HNOI2005]狡猾的商人 并查集好题

    1202: [HNOI2005]狡猾的商人 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2946  Solved: 1384[Submit][Sta ...

  7. windows上配置git

    windows上配置git1.下载mysisigit进入http://msysgit.github.io/,下载,安装,下一步下一步即可. 2.下载tortoisegit进入http://downlo ...

  8. STL--map

    map--概述: 映射(Map)和多重映射(Multimap)是基于某一类型Key的键集的存在,提供对TYPE类型的数据进行快速和高效的检索. l对Map而言,键只是指存储在容器中的某一成员. lMu ...

  9. FlexSlider插件的详细设置参数 http://www.woothemes.com/flexslider/ -----幻灯片插件

    $(window).load(function() { $('.flexslider').flexslider({ namespace: 'flex-', //控件的命名空间,会影响样式前缀 anim ...

  10. JavaScript算法题之–随机数的生成

    JavaScript算法题之–随机数的生成 需求描述:从一组有序的数据中生成一组随机并且不重复的数,类似于简单的抽奖程序的实现. 先来生成一个有序的数组: 1 var arr = [], 2      ...