码迷,mamicode.com
首页 > 其他好文 > 详细

hdu4731(字符串构造+找规律)

时间:2014-08-24 18:07:43      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:acm   hdu   

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 <= 105)
 

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,每种情况唯一,打表输出即可

hdu4731(字符串构造+找规律)

标签:acm   hdu   

原文地址:http://blog.csdn.net/cq_phqg/article/details/38797051

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!