http://www.elijahqi.win/archives/412
Girls’ research
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2705 Accepted Submission(s): 1026
Problem 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 babd
a abcd
Sample Output
0 2
aza
No solution!
Author
wangjing1111
Source
2010 “HDU-Sailormoon” Programming Contest
Recommend
lcy | We have carefully selected several similar problems for you: 3293 3288 3295 3292 3291
需要翻译一下原串,其他没什么难的吧
#include<cstdio>
#include<cstring>
#define N 220000
char a[N],change[5],b[N<<1];
inline int min(int x,int y){
return x<y?x:y;
}
int p[N<<1];
int main(){
freopen("hdu3294.in","r",stdin);
//freopen("hdu3294.out","w",stdout);
int mx,id,ans,ansst;
while (~scanf("%s",change)){
memset(p,0,sizeof(p));
scanf("%s",a);ans=0;
int n=strlen(a);
for (int i=0;i<n;++i){
if (a[i]-change[0]+'a'>='a'){
a[i]-=change[0]-'a';
}else{
a[i]='z'-change[0]+a[i]+1;
}
}
//printf("%s\n",a);
for (int i=1;i<=n;++i){
b[i<<1]=a[i-1];b[(i<<1)-1]='#';
}
b[(n<<1)+1]='#';
n<<=1;n+=1;
mx=id=0;
for (int i=1;i<=n;++i){
if (i<mx) p[i]=min(mx-i,p[(id<<1)-i]);else p[i]=1;
while (b[i+p[i]]==b[i-p[i]]&&i-p[i]>0&&i+p[i]<=n) ++p[i];
if (i+p[i]>mx) mx=i+p[i],id=i;
if (ans<p[i]) ans=p[i],ansst=i-p[i]+1;
}
ans-=1;
if (ans<2) {
printf("No solution!\n");continue;
}
if (ansst%2==1) ansst+=1;
ansst>>=1;//printf("%d\n",ansst);
printf("%d %d\n",ansst-1,ansst+ans-2);
for (int i=ansst;i<ansst+ans;++i) printf("%c",a[i-1]);
printf("\n");
}
return 0;
}