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. 执行: python manage.py makemigrations报AttributeError: 'str' object has no attribute 'decode'

    找到错误代码(line146):query = query.encode(errors='replace') 解决方法:把decode改为encode即可.

  2. paramiko 模块封装

    #!/usr/bin/env python#coding=utf-8 import paramiko, getpass,sys,traceback class ssh_utils(): def log ...

  3. XSS的各种用途

    0x01 最常见之窃取用户cookie 当cookie没有设置HttpOnly属性时,可以通过javascript代码创建img,script,iframe等标签,并把src属性设置为自己部署的xss ...

  4. C语言学习笔记--字符串

    字符串是有序字符的集合,C 语言中没有字符串的概念,而是通过特殊的字符数组模拟字符串,是以'\0'结尾的字符数组. 1.字符数组与字符串 (1)在 C 语言中,字双引号引用的单个或多个字符是一种特殊的 ...

  5. 『原』在Linux下反编译Android .apk文件 使用apktool dex2jar JD-eclipse

    一.使用apktool 将 apk反编译生成程序的源代码和图片.XML配置.语言资源等文件 具体步骤: (1)下载反编译工具包:apktool 官方的打不开 http://apktool.shouji ...

  6. ie7下z-index失效问题解决方法

    绝对定位元素的“有定位属性(relative或absolute)的父元素”在渲染层次时起到了主要作用,前面的被后面的覆盖了.解决办法就是给有定位属性的父元素设置z-index 解决办法: 父级元素加上 ...

  7. c#循环语句 for 循环嵌套的练习。还有跳转语句,异常语句,迭代穷举介绍

    先说一下循环嵌套:循环嵌套就是再一个循环里面再放一个循环,也就是说如果没一个循环都循环10次,那么第一个循环是1的时候,嵌套的循环会循环十次.也就是10*10的效果. for 循环语句 主要还是逻辑思 ...

  8. ReentrantLock简单实现2

    ReentrantLock: /** * ReentrantLock测试逻辑类 */ public class MyService { private Lock lock = new Reentran ...

  9. keystone组件

    引:  什么是keystone    为何要有keystone     keystone的功能     keystone概念详解     keystone与openstack其他组件关系      k ...

  10. 添加超级链接为什么用a标签

    a是anchor的简写,中文意思是锚点,而锚点的引申意思是连接,link已经被html占用了,只能用a来表示连接了.