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. nodejs链接mysql数据库,执行简单的增删改查操作

    var mysql = require('mysql'); var conn = mysql.createConnection({ host: 'localhost', user: 'root', p ...

  2. Cheatsheet: 2014 06.01 ~ 06.30

    Mobile Developing iOS8 Apps Using Swift – Part 1- Hello World The Insider's Guide to Android Intervi ...

  3. MYSQL主键自动增加的配置及auto_increment注意事项

    文章一 原文地址: http://ej38.com/showinfo/mysql-202971.html 文章二:   点击转入第二篇文章 在数据库应用,我们经常要用到唯一编号.在MySQL中可通过字 ...

  4. HTML Meta标签中的viewport属性含义及设置

    两篇文章 第1篇文章 第2篇文章 http://blog.hexu.org/archives/1947.shtml 随着高端手机(Andriod,Iphone,Ipod,WinPhone等)的盛行,移 ...

  5. ADC驱动器或差分放大器设计指南

    作为应用工程师,我们经常遇到各种有关差分输入型高速模数转换器(ADC)的驱动问题.事实上,选择正确的ADC驱动器和配置极具挑战性.为了使鲁棒性ADC电路设计多少容易些,我们汇编了一套通用“路障”及解决 ...

  6. 序列化、反序列化(实体类或要序列化的对象类必须实现Serializable接口)

    package com.phone.shuyinghengxie; import java.io.Serializable; /* 一个类的对象要想序列化成功,必须满足两个条件: 该类必须实现 jav ...

  7. poj 1502 最短路+坑爹题意

    链接:http://poj.org/problem?id=1502 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  8. jquery的隐式类型转换

    jquery的选择器想用变量来传,然后就纠结怎么写引号的问题??? 当时脑子就犯轴了,这个我要是传变量怎么写引号啊,我要是在最外层在加一层引号就不对了,就没法识别变量了,不加反而对了 那就用conso ...

  9. sp_getTable_data

    CREATE PROC sp_Select_Table ) AS begin ) SET @sql='SELECT * FROM ' + @TableName EXEC (@sql) end GO

  10. TAROT.

    /* * * */ #include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int t ...