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. ABAP Enhancement:第一部分

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

  2. POJ 2431 Expedition(探险)

    POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of co ...

  3. Shell Sort(草稿)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Shel ...

  4. windows上配置git

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

  5. WCF学习资源收集汇总

    1.WCF编程 http://www.cnblogs.com/wengyuli/category/217446.html 2.wcf热门问题编程示例 http://blog.csdn.net/book ...

  6. LINQ 如何实现 in 与 not in

    T-SQL的IN: Select ProductID, ProductName, CategoryID From dbo.Products Where CategoryID , ) T-SQL的NOT ...

  7. iOS - OC RunTime 运行时

    1.运行时的使用 向分类中添加属性 // 包含运行时头文件 #import <objc/runtime.h> /* void objc_setAssociatedObject(id obj ...

  8. Android 四种简单的动画(淡入淡出、旋转、移动、缩放效果)

    最近在Android开发当中,用到的动画效果. public void onClick(View arg0) { // TODO 自动生成的方法存根 switch (arg0.getId()) { c ...

  9. Python学习笔记17—Tornado

    实例 #!/usr/bin/env Python #coding:utf-8 import tornado.httpserver import tornado.ioloop import tornad ...

  10. linux的ulimit命令

    ulimit命令用来限制系统用户对shell资源的访问. 语法: ulimit [-acdfHlmnpsStv] [size] 选项介绍:    -a 显示当前所有的资源限制;    -c size: ...