kuangbin专题十六 KMP&&扩展KMP HDU3294 Girls' research
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.
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的更多相关文章
- 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 ...
- kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...
- 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 ...
- kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans
The Genographic Project is a research partnership between IBM and The National Geographic Society th ...
- kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...
- kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条
一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...
- kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- 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 ...
随机推荐
- When install ”matplotlib” with ”pip”, if you get the following error, it means the “freetype” and “png” libraries needed by matplotlib are not installed:
============================================================================ * The following require ...
- [mpm_winnt:error] [pid 28120:tid 15980] (OS 10038)在一个非套接字上尝试了一个操作。 : AH00332: winnt_accept: getsockname error on listening socket, is IPv6 available?
解决办法一: 可能是安装了某些程序修改了Winsock,使用netsh winsock reset 命令修复Winsock重启计算机即可! 解决办法二: 在httpd.conf文件中添加 Win32D ...
- Shell编程进阶 1.3data命令
date命令是显示日期时间的命令 date 2016年 01月 01日 星期五 15:05:01 CST 修改时间的选项是 -s date -s "2016-01-01 12:56:10&q ...
- python的面向对象编程
面向对象编程是一种程序的范式,它把程序看成是对不同对象的相互调用,对现实世界建立的一种模型. 面向对象编程的基本思想,类和实例.类用于定义抽象对象,实例根据类的定义被创建出来. 在python当中我们 ...
- 【总结整理】openlayer
实时路况 http://www.cnblogs.com/gisvip/archive/2012/11/24/2787141.html
- ROS探索总结(四)——简单的机器人仿真
前边我们已经介绍了ROS的基本情况,以及新手入门ROS的初级教程,现在就要真正的使用ROS进入机器人世界了.接下来我们涉及到的很多例程都是<ROS by Example>这本书的内容,我是 ...
- 提取a标签的链接文字
在seg上看到一个问题 <a href="http://www.abc.com/thread-4131866-1-1.html" class="s xst" ...
- Edison UVALive3488
传送门 题目大意 有一个0~n-1的序列,有m次操作,操作包含三个元素:pl,len,ti,表示这个操作进行ti次,每次将从pl+1开始的len个元素移到序列头部.分析 看到题不难想到使用平衡树将需移 ...
- Mysql 大数据量导入程序
Mysql 大数据量导入程序<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" ...
- Html.DropDownListFor 练习
需要创建一个List<SelectListItem>数据集,如下 使用已经存在FruitCategoryEntity.cs类的IEnumerable<FruitCategory> ...