首页 技术 正文
技术 2022年11月15日
0 收藏 467 点赞 3,252 浏览 2049 个字

http://acm.hdu.edu.cn/showproblem.php?pid=3294

Girls’ research

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status Practice HDU 3294

Description

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. 

Input

Input 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. 

Output

Please 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 babda abcd  

Sample Output

0 2azaNo solution! 只要找到起始点,一切就OK了!!!

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>using namespace std;
#define INF 0x3f3f3f3f
#define N 1000007char s[N], S[N], str[N];
int p[N], Mid;int Manacher()
{
int MaxLen = , index = , ans = ;
int len = strlen(s);
Mid = ; for(int i=; i<len; i++)
{
if(MaxLen>i) p[i] = min(p[index*-i], MaxLen-i);
else p[i] = ; while(s[i-p[i]]==s[i+p[i]] )
p[i]++; if(p[i]+i>MaxLen)
{
MaxLen = p[i] + i;
index = i;
} if(p[i]>ans)
{
ans = p[i];
Mid = i;
}
}
return ans-;
}int main()
{
char ch[]; while(scanf("%s%s", ch, S)!=EOF)
{
int i, len = strlen(S), number;
char c; number = ch[]-'a'; s[] = '$';
for(i=; i<len; i++)
{
c = S[i] - number;
if(c<'a')
c += ;
S[i] = c; s[i*+] = '#';
s[i*+] = S[i];
}
s[i*+] = '#';
s[i*+] = ; int ans = Manacher(); if(ans<)
printf("No solution!\n");
else
{
int L = Mid/-(ans+)/;
printf("%d %d\n", L, L+ans-);
memset(str, , sizeof(str));
strncpy(str, S+L, ans);
printf("%s\n", str);
}
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,997
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,356
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,139
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848