HDU3294 Girls' research

来源:互联网 发布:丁克 知乎 编辑:程序博客网 时间:2024/05/16 06:11

Girls' research

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1298    Accepted Submission(s): 493


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

Sample Output
0 2azaNo solution!
 

Author
wangjing1111
 

Source
2010 “HDU-Sailormoon” Programming Contest 

题意:给出一个字母,例如b,那么b就是真正的a,c就是真正的b,再给出一个 字符串,让你求出最大回文串。
分析:manacher算法,改一点点东西就行了。

<span style="font-size:18px;">#include <iostream>#include <cstdio>#include <cstring>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <cmath>#include <algorithm>using namespace std;const double eps = 1e-6;const double pi = acos(-1.0);const int INF = 0x3f3f3f3f;const int MOD = 1000000007;#define ll long long#define CL(a,b) memset(a,b,sizeof(a))#define MAXN 200010char ch,str[MAXN*2],s[MAXN];int p[MAXN*2];int pre,maxx;void init(){    int i,l;    CL(str, '\0');///初始化str    str[0] = '$'; str[1] = '#';    for(i=0,l=2; s[i]; i++,l+=2)    {        str[l] = s[i];        str[l+1] = '#';    }}void solve(){    int id;    int mx = 0;    maxx = 0;    for(int i=1; str[i]; i++)    {        if(mx > i) p[i]=p[2*id-i]>(mx-i)?(mx-i):p[2*id-i];        else p[i] = 1;        while(str[i-p[i]] == str[i+p[i]]) p[i]++;        if(p[i]+i > mx)        {            mx = p[i] + i;            id = i;        }        if(maxx < p[i])        {///记录最长回文点的位置            maxx = p[i]; pre = i;           // cout<<str<<endl;            //printf("maxx=%d pre=%d\n",maxx,pre);        }    }    maxx--;}int main(){    while(scanf("%c%s",&ch,s)==2)    {        getchar();        int x = ch - 'a';        for(int i=0; s[i]; i++)        {            int t = s[i] - 'a';            s[i] = (t - x + 26)%26 + 'a';        }        init();        solve();        int r = pre/2 + maxx/2 - 1;        int l = r - maxx + 1;        if(maxx > 1)        {            printf("%d %d\n",l,r);            for(int i=l; i<=r; i++)                printf("%c",s[i]);            printf("\n");        }        else printf("No solution!\n");    }    return 0;}</span>



0 0
原创粉丝点击