HDU - 3294Girls' research(马拉车的应用)
题目描述
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
1 | b babd |
Sample Output
1 | 0 2 |
题解
题意:
- 一开始输入的字母起得是变换作用, 比如, 若输入b, 就把原来子串所有字母减一, 若输入z 就把所有字母加一。 当着这个条件最后输出的时候变换一下就行, 不用把整个串变换。
- 找出最长回文串, 若长度相同只取最先出现的。
要是不明白马拉车的实现原理, 那就给你推荐两篇博客:
博客1
博客2
关键就是在这两步的处理上, 详情看代码注释
AC代码
1 |
|
1 | 恰似你一低头的温柔,娇弱水莲花不胜寒风的娇羞, 我的心为你悸动不休。 --mingfuyan |
原文作者: Mingfu Yan
原文链接: https://solodance.top/2020/06/26/HDU - 3294Girls' research(马拉车的应用)/
版权声明: 转载请注明出处(必须保留作者署名及链接)