HDU 3294 Girls' research
来源:互联网 发布:网络墨迹是什么意思 编辑:程序博客网 时间:2024/05/21 13:56
Girls' research
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
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 babda abcd
Sample Output
0 2azaNo solution!
题意是给定一个字符和一个字符串,根据字符可以得到新的字母表的对应关系,求新的对应关系下的最长的回文序列,最后打印出最长的回文序列。
先替换成对应关系的字符串,然后用Manacher算法求解最长回文串长度,并记录对应位置,最后根据位置和长度求解区间左右端点。
代码如下:
/*************************************************************************> File Name: Girls_research.cpp> Author: ZhangHaoRan> Mail: chilumanxi@gmail.com> Created Time: 2016年03月05日 星期六 11时35分08秒 ************************************************************************/#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<vector>#include<set>#include<map>#include<queue>#include<list>#include<algorithm>using namespace std;const int MAXN = 200010;char Ma[MAXN * 2];int Mp[MAXN * 2];char s[MAXN];int len;void Manacher(){ int l = 0; Ma[l ++] = '$'; Ma[l ++] = '#'; for(int i = 0; i < len ; i ++){ Ma[l ++] = s[i]; Ma[l ++] = '#'; } Ma[l] = 0; int mx = 0, id = 0; int ans = 0; int anspos = 0; for(int i = 0; i < l; i ++){ Mp[i] = mx > i ? min(Mp[2 * id - i], mx - i) : 1; while(Ma[i + Mp[i]] == Ma[i - Mp[i]]) Mp[i] ++; if(Mp[i] + i > mx){ mx = Mp[i] + i; id = i; } if(ans < Mp[i] - 1){ ans = Mp[i] - 1; anspos = i; } } if(ans < 2){ cout << "No solution!" << endl; return ; } int tempa = (anspos - ans) / 2; int tempb = (anspos + ans - 4 + 1) / 2; printf("%d %d\n", tempa, tempb); for(int i = tempa; i <= tempb; i ++) putchar(s[i]); cout << endl; }int main(void){ char ch; while(~scanf("%c%s", &ch, s)){ getchar(); int ind = ch - 'a'; len = strlen(s); for(int i = 0; i < len; i ++){ s[i] = s[i] - ind < 'a' ? s[i] + 26 - ind : s[i] - ind; } Manacher(); } return 0;}
查看原文:http://chilumanxi.org/2016/03/05/hdu-3294-girls-research/
0 0
- hdu 3294 Girls' research
- hdu 3294 Girls' research
- HDU 3294 Girls' research
- hdu 3294 Girls' research
- HDU 3294Girls' research
- [manacher] hdu 3294 Girls' research
- hdu 3294 Girls' research(manacher)
- HDU - 3294 Girls' research(manacher)
- hdu 3294 Girls' research【manacher】
- HDU 3294 Girls’ research Manacher
- HDU 3294 Girls' research 字符串-manacher算法
- HDU 3294 Girls' research (manacher)
- hdu 3294 Girls' research Manacher回文串
- HDU.3294 Girls' research Manacher Algorithm
- HDOJ 3294 Girls' research
- hdu-3249-Girls' research -mancher
- HDU 3294 Girls' research (Manacher算法 + 记录区间)
- HDU 3294 Girls' research (Manacher算法 + 记录区间)
- SecureCRT连接编码错误
- 欢迎使用CSDN-markdown编辑器
- 海盗分金币
- xml基础
- 栈回溯技术arm_v5t_le版
- HDU 3294 Girls' research
- LeetCode : Longest Palindromic Substring [java]
- jdk API标记接口
- 2015 浙江省赛 Beauty of Array (思维题)
- 任性动图V4.0 全新界面 致力于打造 优美、便捷的文字呈现
- 【GeekBand】Android应用界面开发【第一周】学习笔记
- spring
- uva10400 - Game Show Math(回溯+剪枝)
- PythonChallenge之level-0解题报告