hdu 3294 Girls' research(manacher)

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!

题意:给你一个字符表示真正的a 然后要你求解码以后的最长回文序列

思路:先manacher处理一下 然后从头到尾解码即可

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define ll long long int
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
int p[]; //注意数组的大小 要开2倍
void manacher(string s){
string temp="";
temp+="$#";
int len=s.length();
for(int i=;i<len;i++){
temp+=s[i];
temp+="#";
}
len=temp.length();
int po=; int mx=;
for(int i=;i<len;i++){
p[i]=mx>i?min(p[*po-i],mx-i):;
while(temp[p[i]+i]==temp[i-p[i]]) p[i]++;
if(i+p[i]>mx){
mx=p[i]+i;
po=i;
}
}
}
int main(){
ios::sync_with_stdio(false);
char real;
string s;
while(cin>>real>>s){
manacher(s);
int len=s.length();
int ans=;
int sp=-;
for(int i=;i<*len+;i++){
if(ans<p[i]-){
ans=p[i]-;
sp=(i-p[i])/;
}
}
if(sp==-){
cout<<"No solution!"<<endl;
}else{
cout<<sp<<" "<<sp+ans-<<endl;
for(int i=sp;i<=sp+ans-;i++)
cout<<char((s[i]-real+)%+'a');
cout<<endl;
}
}
return ;
}
上一篇:【BZOJ-3790】神奇项链 Manacher + 树状数组(奇葩) + DP


下一篇:新浪微博的账号登录及api操作