hdu4731(字符串構造+找規律)
Minimum palindrome
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 780 Accepted Submission(s): 353
Problem Description
Setting password is very important, especially when you have so many "interesting" things in "F:\TDDOWNLOAD".
We define the safety of a password by a value. First, we find all the substrings of the password. Then we calculate the maximum length of those substrings which, at the meantime, is a palindrome.
A palindrome is a string that will be the same when writing backwards. For example, aba, abba,abcba are all palindromes, but abcab, abab are not.
A substring of S is a continous string cut from S. bcd, cd are the substrings of abcde, but acd,ce are not. Note that abcde is also the substring of abcde.
The smaller the value is, the safer the password will be.
You want to set your password using the first M letters from the alphabet, and its length should be N. Output a password with the smallest value. If there are multiple solutions, output the lexicographically smallest one.
All the letters are lowercase.
Input
The first line has a number T (T <= 15) , indicating the number of test cases.
For each test case, there is a single line with two integers M and N, as described above.(1 <= M <= 26, 1 <= N <= 10
5)
Output
For test case X, output "Case #X: " first, then output the best password.
Sample Input
2
2 2
2 3
Sample Output
Case #1: ab
Case #2: aab
題意:用前m個小寫字母構造出一個長度為n的字符串,要求該字符串的最長回文子串盡量短,輸出滿足條件中字典序最小的一個
思路:找規律題
1. m=1時,答案為aaaa.....
2. m>=3時,答案為abcabc........
3. m=2時,分n討論
1. n>8時,最小回文長度為4,由aababb構造成,注意在最前面還要加上aa,可以滿足字典序最小,最後若字符串剩下的長度小於6打表輸出每種對應的情況即可
2. n<=8時,最小回文長度小於4,每種情況唯一,打表輸出即可