HDU 3294 Girls' research 【最长回文串+字符周期变换】
来源:互联网 发布:怎么看淘宝号有几颗心 编辑:程序博客网 时间:2024/05/18 03:32
Girls' research
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1900 Accepted Submission(s): 721
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!
题意:给一个串只含小写字符,问最长回文串,在原串出现的初始位置和末尾置,有方案时输出最长回文串经过转换后的串,多种方案输出先出现的,否则输出一个标识符 转化是给一字符代替a 如让b代替a 串azb就是zya;
思路:就两个问题,一个是找到最长回文串,第二是经过字符转换后输出,细分析一下两个问题没有交集,同一个字符转换后还是相同的,所以先求出最长回文串,再转化即可;
失误:题意看错了输出说输出第一个,就没考虑最长的,WA了好几次之后才发现让求什么都不知道;
转化过程自己想的太麻烦了 如原串的第i位的字符str[i]=S[(i+1)<<1] ,求beg end直接逆过程喽 还有转化字符 字符直接减代替a的字符 再判断是否小于0,小于0再加个 26就转化成功了,自己想的太麻烦了;
AC代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MAXN=5*1e5+55;char str[MAXN],S[MAXN]; int p[MAXN];int Manacher(char *S){int id=0,mx=0,i=0,ans=0; memset(p,0,sizeof(p));for(i=1;S[i];++i) {p[i]=mx>i?min(mx-i,p[(id<<1)-i]):1;while(S[i+p[i]]==S[i-p[i]]) ++p[i];if(i+p[i]>mx) {mx=i+p[i]; id=i;}if(p[i]>p[ans]){ans=i;}}return ans;}int main(){int i; char s[2];while(~scanf("%s %s",s,str)){S[0]='$'; S[1]='#';for(i=0;str[i];++i) {S[(i+1)<<1]=str[i];S[((i+1)<<1)+1]='#';}S[(i+1)<<1]='\0';int pos=Manacher(S);if(p[pos]-1>=2) {int end=((pos+p[pos]-1-1)>>1)-1,beg=(pos-p[pos]+2)/2-1;printf("%d %d\n",beg,end);for(i=beg;i<=end;++i) {printf("%c",(char)(((str[i]-s[0])%26+26)%26+'a'));}printf("\n");}else printf("No solution!\n");}return 0; }
0 0
- HDU 3294 Girls' research 【最长回文串+字符周期变换】
- HDU 3294 Girls' research【最长回文子串】
- Girls' research 最长回文串
- hdu 3294 Girls' research Manacher回文串
- hdoj 3294 Girls' research 【Manacher算法】【输出最长回文子串 + 字符转化】
- HDU 3294Girls' research最长回文子串(暴力和manacher 两种解法)
- 【回文串】HDU 3294 Girls' research manacher算法
- hdu 3294 Girls' research
- hdu 3294 Girls' research
- HDU 3294 Girls' research
- hdu 3294 Girls' research
- HDU 3294Girls' research
- HDU 3294 Girl's research(最长回文子串)
- HDU 3294 Girls' research(Manacher算法求回文串左右端点)
- [manacher] hdu 3294 Girls' research
- hdu 3294 Girls' research(manacher)
- HDU - 3294 Girls' research(manacher)
- hdu 3294 Girls' research【manacher】
- 占位
- 占位
- mac记录
- 更新metasploit
- MyBatis进阶
- HDU 3294 Girls' research 【最长回文串+字符周期变换】
- linux进程间通信IPC
- java调用JS 与JS 调java
- Python selenium —— 一定要会用selenium的等待,三种等待方式解读
- codeforces基础题——#357(div2) D
- ubuntu 16.04 phpEclipse插件安装及配置Xdebug
- AsyncLoader - Android中的异步加载器
- xampp +phpstrom环境配置
- 我学Hibernate - 02 (加入注解方式)