首页 > 代码库 > HDU3294 Girls' research
HDU3294 Girls' research
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.
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.
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.
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
field=problem&key=2010+%A1%B0HDU-Sailormoon%A1%B1+Programming+Contest&source=1&searchmode=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 200010 char 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>
HDU3294 Girls' research
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。