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 ...
随机推荐
- PowerDesigner CDM中取消默认不能存在同名主键的方法
This data item is already used in a primary identifier.Normalization rules prevent ... 处理的方法为: 菜单栏上的 ...
- Django 学习之---静态文件处理详解
前言: 1.静态文件是指 网站中的 js, css, 图片,视频等文件 2.静态文件放在对应的 app 下的 static 文件夹中 或者 STATICFILES_DIRS 中的文件夹中. 当 DEB ...
- DAY19-Django之model进阶
QuerySet 可切片 使用Python 的切片语法来限制查询集记录的数目 .它等同于SQL 的LIMIT 和OFFSET 子句. >>> Entry.objects.all()[ ...
- JSONP跨域提交表单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- hibernateTemplate方法使用
- ionic 页面乱码
是文本编辑器的问题.文本编辑器保存时默认保存成Encoding:ANSI编码格式,保存成utf-8就好了
- ROS Learning-015 learning_tf(编程) 编写一个监听器程序 (Python版)
ROS Indigo learning_tf-02 编写一个 监听器 程序 (Python版) 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu 1 ...
- p1129 [ZJOI2007]矩阵游戏
传送门 分析 不难想到将黑点的行列连边,然后判断最大匹配是否等于n 代码 #include<iostream> #include<cstdio> #include<cst ...
- 手动通知扫描SD卡主动生成缩略图
最近做项目遇到的难题,调用系统拍照获取不到缩略图,非得关机重启才会生成,所以我们要主动通知系统扫描SD卡生成缩略图, 在Android4.4之前也就是以发送一个Action为“Intent.ACTIO ...
- 【C#】 WebApi 路由机制剖析
C#进阶系列——WebApi 路由机制剖析:你准备好了吗? 转自:https://blog.csdn.net/wulex/article/details/71601478 2017年05月11日 10 ...