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 ...
随机推荐
- vue-cli脚手架build目录中的dev-server.js配置文件
本文系统讲解vue-cli脚手架build目录中的dev-server.js配置文件 这个配置文件是命令npm run dev 和 npm run start 的入口配置文件,主要用于开发环境 由于这 ...
- #关于 OneVsRestClassifier(LogisticRegression(太慢了,要用超过的机器)
#关于 OneVsRestClassifier #注意以下代码中,有三个类 from sklearn import datasets X, y = datasets.make_classificati ...
- python+requests+excel 接口测试
1.EXCEL文件接口保存方式,如图. 2.然后就是读取EXCEL文件中的数据方法,如下: import xlrd class readExcel(object): def __init__(self ...
- python爬虫--编码问题y
1)中文网站爬取下来的内容中文显示乱码 Python中文乱码是由于Python在解析网页时默认用Unicode去解析,而大多数网站是utf-8格式的,并且解析出来之后,python竟然再以Unicod ...
- createPlaceholder 函数
function createPlaceholder(id,text,top,left){ top = top || 0; left = left || 0; var obj = $('#' + id ...
- Jsonp实现跨域请求Ajax
客户端 #!/usr/bin/env python import tornado.ioloop import tornado.web class MainHandler(tornado.web.Req ...
- activity状态保存的bundl对象存放位置的思考
我们知道,当activity被异常终止时,可以把一些信息保存到bundle对象中,在下次启动时恢复. 那么,这个bundle对象是保存在哪里的呢? 这种状态保存的方法针对的是activity而不是进程 ...
- 洛谷P2146 树链剖分
题意 思路:直接树链剖分,用线段树维护即可,算是树剖的经典题目吧. 代码: #include <bits/stdc++.h> #define ls(x) (x << 1) #d ...
- 算法Sedgewick第四版-第1章基础-019一Scanner的用法
package algorithms.fundamentals001; import java.util.Locale; import java.util.Scanner; import algori ...
- java中的全局变量与静态变量的区别与联系?有时候为什么专门定义静态变量。(标题党~~)
static代表“每个类一个”而不是“每个对象一个”.即静态变量是类的所有对象共有的. 1 static JFrame f; static MyDrawPanel ml; 整个应用程序如下: 定义在p ...