http://acm.hdu.edu.cn/showproblem.php?pid=3294

Girls' research

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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!
 
只要找到起始点,一切就OK了!!!
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm> using namespace std;
#define INF 0x3f3f3f3f
#define N 1000007 char s[N], S[N], str[N];
int p[N], Mid; int Manacher()
{
int MaxLen = , index = , ans = ;
int len = strlen(s);
Mid = ; for(int i=; i<len; i++)
{
if(MaxLen>i) p[i] = min(p[index*-i], MaxLen-i);
else p[i] = ; while(s[i-p[i]]==s[i+p[i]] )
p[i]++; if(p[i]+i>MaxLen)
{
MaxLen = p[i] + i;
index = i;
} if(p[i]>ans)
{
ans = p[i];
Mid = i;
}
}
return ans-;
} int main()
{
char ch[]; while(scanf("%s%s", ch, S)!=EOF)
{
int i, len = strlen(S), number;
char c; number = ch[]-'a'; s[] = '$';
for(i=; i<len; i++)
{
c = S[i] - number;
if(c<'a')
c += ;
S[i] = c; s[i*+] = '#';
s[i*+] = S[i];
}
s[i*+] = '#';
s[i*+] = ; int ans = Manacher(); if(ans<)
printf("No solution!\n");
else
{
int L = Mid/-(ans+)/;
printf("%d %d\n", L, L+ans-);
memset(str, , sizeof(str));
strncpy(str, S+L, ans);
printf("%s\n", str);
}
}
return ;
}

(回文串 Manacher )Girls' research -- hdu -- 3294的更多相关文章

  1. Girls' research - HDU 3294 (Manacher处理回文串)

    题目大意:给以一个字符串,求出来这个字符串的最长回文串,不过这个字符串不是原串,而是转换过的,转换的原则就是先给一个字符 例如 'b' 意思就是字符把字符b转换成字符 a,那么c->b, d-& ...

  2. HDU 3613 Best Reward ( 拓展KMP求回文串 || Manacher )

    题意 : 给个字符串S,要把S分成两段T1,T2,每个字母都有一个对应的价值,如果T1,T2是回文串,那么他们就会有一个价值,这个价值是这个串的所有字母价值之和,如果不是回文串,那么这串价值就为0.问 ...

  3. (回文串 )Best Reward -- hdu -- 3613

    http://acm.hdu.edu.cn/showproblem.php?pid=3613 Best Reward Time Limit: 2000/1000 MS (Java/Others)    ...

  4. 最长回文---hdu3068 (回文串 manacher 算法模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068 题意很清楚:就是求一个串s的子串中最长回文串的长度:这类题用到了manacher算法 #incl ...

  5. BZOJ 2342 回文串-Manacher

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2342 思路:先跑一遍Manacher求出p[i]为每个位置为中心的回文半径,因为双倍回文串 ...

  6. BZOJ 2565 回文串-Manacher

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2565 题意:中文题 思路:定义L[i],R[i].表示以i为左端点/右端点时,最长回文串长 ...

  7. POJ 3974 回文串-Manacher

    题目链接:http://poj.org/problem?id=3974 题意:求出给定字符串的最长回文串长度. 思路:裸的Manacher模板题. #include<iostream> # ...

  8. 【回文串-Manacher】

    Manacher算法能够在O(N)的时间复杂度内得到一个字符串以任意位置为中心的回文子串.其算法的基本原理就是利用已知回文串的左半部分来推导右半部分. 转:http://blog.sina.com.c ...

  9. BZOJ 2565: 最长双回文串 [Manacher]

    2565: 最长双回文串 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1842  Solved: 935[Submit][Status][Discu ...

  10. BZOJ.2565.[国家集训队]最长双回文串(Manacher/回文树)

    BZOJ 洛谷 求给定串的最长双回文串. \(n\leq10^5\). Manacher: 记\(R_i\)表示以\(i\)位置为结尾的最长回文串长度,\(L_i\)表示以\(i\)开头的最长回文串长 ...

随机推荐

  1. How to Pronounce EVERY

    How to Pronounce EVERY Share Tweet Share Tagged With: 2-Syllable Everybody should learn the word ‘ev ...

  2. iKcamp|基于Koa2搭建Node.js实战(含视频)☞ 规范与部署

    沪江CCtalk视频地址:https://www.cctalk.com/v/15114923889450 规范与部署 懒人推动社会进步. 本篇中,我们会讲述三个知识点 定制书写规范 开发环境运行 如何 ...

  3. Extending Conductor

    后端 导体提供了可插拔的后端.目前的实现使用Dynomite. 每个后端需要实现4个接口: //Store for workflow and task definitions com.netflix. ...

  4. 各种id生成策略

    package com.taotao.utils; import java.util.Random; /** * 各种id生成策略 */ public class IDUtils { /** * 图片 ...

  5. C# split分割多个字符

    string[] myAgent = agentInfo.Split(new string[] { "$#$" }, StringSplitOptions.None);

  6. 用Python提取XML里的内容,存到Excel中

    最近做一个项目是解析XML文件,提取其中的chatid和lt.timestamp等信息,存到excel里. 1.解析xml,提取数据 使用python自带的xml.dom中的minidom(也可以用l ...

  7. 利用简单的参数传递来实现单条查询的easyui-datagrid

    前一阵子老师给出了一个题目, 说让设计个表格, 学生系统的, 可以查询学生的信息和成绩, 科目自己定, 数据库建表也自己定. 数据库的建表可是建的相当的简陋, 反正老师不是很满意, 后来数据表格做出来 ...

  8. 7.Reverse Integer (INT; Overflow)

    Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 思路:要注意溢出 ...

  9. MyBatis配置数据源的两种方式

    ---------------------siwuxie095                                     MyBatis 配置数据源的两种方式         1.配置方 ...

  10. Redis网络协议

    Redis网络协议较为简单,易于阅读. 命令或数据已\r\n结尾,但除了状态回复,其他数据都是二进制安全的(包含长度) 头部如下: + 正确的状态信息,具体信息是当前行+后面的字符. -  一条错误信 ...