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.
InputInput 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.OutputPlease 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! 题目比较裸,直接马拉车即可 复习一下长度,子串的求法 pos 为 回文半径最大的中心
最大回文半径 = maxr = p[pos]
最大回文长度 = maxr - 1
回文起点 = (pos-maxr)/2
 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=;
char s[maxn],snew[*maxn];
int p[*maxn];
char c; void manacher(char* s) {
int l=;
snew[l++]='$';
snew[l++]='#';
for(int i=;s[i];i++) {
snew[l++]=s[i];
snew[l++]='#';
}
snew[l]='\0';
int id=,mx=,pos,maxlen=-;
for(int i=;i<l;i++) {
p[i]=mx>i?min(p[id*-i],mx-i):;
while(snew[i-p[i]]==snew[i+p[i]]) p[i]++;
if(i+p[i]>mx) {
mx=i+p[i];
id=i;
}
if(p[i]>maxlen) {
maxlen=p[i];
pos=i;
}
}
// printf("%d**\n",maxlen);
if(maxlen<=) printf("No solution!");
else {
printf("%d %d\n",(pos-maxlen)/,(pos+maxlen)/-);
for(int i=(pos-maxlen)/;i<=(pos+maxlen)/-;i++) {
printf("%c",'a'+(s[i]-c+)%);
}
printf("\n");
}
}
int main() {
//freopen("in","r",stdin);
while(~scanf("%c",&c)) {
scanf("%s\n",s);
manacher(s);
}
return ;
}

kuangbin专题十六 KMP&&扩展KMP HDU3294 Girls' research的更多相关文章

  1. kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)

    Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...

  2. kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity

    Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...

  3. kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings

    You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...

  4. kuangbin专题十六 KMP&&扩展KMP HDU3336 Count the string

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

  5. kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans

    The Genographic Project is a research partnership between IBM and The National Geographic Society th ...

  6. kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace

    CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...

  7. kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条

    一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...

  8. kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo

    The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...

  9. kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence

    Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...

随机推荐

  1. unittest添加测试用例方法

    1. suite=unittest.TestLoader().loadTestsFromTestCase(changedTestHJ)unittest.TextTestRunner(verbosity ...

  2. python的raw_input()函数。 函数的可变对象和不可变对象作为参数传递。

    python的raw_input()函数, 接受键盘输入, 其返回值是字符串类型, 所以当输入的是数字时, 如果是想参与算术运算, 必须要对其进行类型转换. python的参数传递, 对于可变对象和不 ...

  3. 问题:C# ToString("P");结果:c#中的常用ToString()方法总结

    c#中的常用ToString()方法总结   很多类都重写了ToString方法, 导致很多类的tostring到底执行了什么,有哪些参数,都不清楚 对于int,double等的tostring: C ...

  4. VS2008 C++ 项目怎样添加“依赖”、“库目录”和“包含目录”

    随笔 - 79, 文章 - 0, 评论 - 7, 引用 - 0 1. 添加编译所需要(依赖)的 lib 文件 [解决方案资源管理器]“项目->属性->配置属性->连接器->输入 ...

  5. UML在软件开发中各个阶段的作用和意义

    经典的软件工程思想将软件开发分成5个阶段:需求分析,系统分析与设计,系统实现,测试及维护五个阶段. 之所以如此,是因为软件开发中饣含了物和人的因素,存在着很大的不确定性,这使得软件工程不可能像理想的, ...

  6. LAMP 2.3 Apache配置防盗链

    如果你的站点是一个图片站,有很多非常漂亮的美女图片,那我相信,时间久了会有很多人来你网站借图片,有的人直接下载走了,还有的人直接取走图片的地址,比如你的网站域名是 www.123.com,图片地址为 ...

  7. C语言学习笔记--数组参数和指针参数

    1. 数组参数退化为指针的意义 (1)C 语言中只会以值拷贝的方式传递参数,当向函数传递数组时,将整个数组拷贝一份传入函数导致执行效率低下,C 语言以高效作是最初的设计目标,所以这种方法是不可取的. ...

  8. DAY11-MYSQL数据操作

    一 介绍 MySQL数据操作: DML ======================================================== 在MySQL管理软件中,可以通过SQL语句中的 ...

  9. Python之整数,浮点数和布尔类型

    整数和浮点数有那个四则运算: 两种类型的数可以直接进行加减,当整数和浮点数进行加减的时候,结果会自动的变为浮点数,其中除法运算是“/”来表示的, 而余数的算术符号是“%”来表示的.如果是为了求除完后的 ...

  10. html标签的显示模式(块级标签,行内标签,行内块标签)(转)

    html标签的显示模式(块级标签,行内标签,行内块标签)   今天讲课的时候,讲到了html中的标签的显示模式,大致分为块级标签和行内标签.那么初学者在刚使用标签的时候会发现有些属性在一些标签上不起作 ...