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. [转][Unreal3教程]引擎使用操作入门教程

    前言 如果你想转载这篇文章,请不要把这篇文章的来源去掉:http://blog.sina.com.cn/zjmjeo 一来是对我辛苦写这篇文章肯定,二来我可以有更多机会和你们这些朋友交流 1.打开引擎 ...

  2. 用iconv指令解决utf8和gb18030编码间转换

    Linux显示在Windows编辑过的中文就会显示乱码是由于两个操作系统使用的编码不同所致.Linux下使用的编码是utf8,而Windows使用的是gb18030.  解决方案:  在终端中,进入到 ...

  3. Codeforces Round #237 (Div. 2) B题模拟题

    链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...

  4. 使用Invoke、委托函数

    //Invoke(new MethodInvoker(delegate() //{ // DataBind(); //}));

  5. 百度翻译word-wrap,页面错乱原因查找过程(已修复)

    今天群里有人发问, 进入百度翻译http://fanyi.baidu.com/#auto/zh/, 输入word-wrap,发现页面错乱. 寻找错乱原因. 上图 开始查找原因: 1.从请求入手 从ch ...

  6. [转]产品需求文档(PRD)的写作

    产品需求对产品研发而言非常重要,写不好需求,后面的一切工作流程与活动都会受到影响.转载一篇文章,关于产品需求文档写作方面的,如下: 本文摘自(一个挺棒的医学方面专家):http://www.cnblo ...

  7. LightOJ::1077 -----奇妙的最大公约数

    题目:http://www.lightoj.com/volume_showproblem.php?problem=1077 题意:在平面上, 给出两个点的坐标 例如:(x, y) 其中x, y 都是整 ...

  8. MTK Camera 开机启动流程(转载)

    一.MTK平台Camera框架 MTK平台的Camera的架构见下图, 这里主要介绍kernel部分和HAL层部分. 1.Kernel 部分主要有两块: 1.1.image sensordriver, ...

  9. .net 连接sqlserver类库

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Da ...

  10. JavaWeb学习总结(七)—HttpServletRequest

    一.Request概述 request是Servlet.service()方法的一个参数,类型为javax.servlet.http.HttpServletRequest.在客户端发出每个请求时,服务 ...