hdu 4731 Minimum palindrome(网络赛 成都赛区)
来源:互联网 发布:unix网络编程 mobi 编辑:程序博客网 时间:2024/05/20 21:43
Minimum palindrome
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 72 Accepted Submission(s): 26
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.
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)
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
22 22 3
Sample Output
Case #1: abCase #2: aab
#include <iostream>#include <string>using namespace std;string ans[9]={"","a","ab","aab","aabb","aaaba","aaabab","aaababb","aaababbb"};void input(){ int t, n, m, k = 0; cin >> t; while (t--) { cin >> m >> n; cout << "Case #" << ++k << ": "; if (m == 1) { for (int i = 0; i < n; i++) { cout << 'a'; } } else if (m > 2) { for (int i = 0; i < n / 3; i++) { cout << "abc"; } if (n % 3 == 1) { cout << "a"; } else if (n % 3 == 2) { cout << "ab"; } } else { if (n <= 8) { cout << ans[n]; } else { cout << "aa"; n -= 2; for (int i = 0; i < n / 6; i++) { cout << "aababb"; } if (n % 6 == 1) { cout << "a"; } else if (n % 6 == 2) { cout << "aa"; } else if (n % 6 == 3) { cout << "aaa"; } else if (n % 6 == 4) { cout << "aaaa"; } else if (n % 6 == 5) { cout << "aabab"; } } } cout << endl; }}int main(){ std::ios::sync_with_stdio(false); input(); return 0;}
- hdu 4731 Minimum palindrome(网络赛 成都赛区)
- HDU 4731 Minimum palindrome 2013 ACM/ICPC 成都网络赛
- 2013成都网络赛1004题HDU 4731Minimum palindrome (思维题目)
- 2013 成都赛区网赛 D Minimum palindrome
- 2013 成都网络赛 1004 Minimum palindrome
- 成都赛区网络赛 hdu 4292 food
- HDU/HDOJ 4038 2011成都赛区网络赛H题
- 2012 ACM/ICPC 成都赛区网络赛 HDU 4296
- 2013成都赛区网络赛
- HDU: 4731 Minimum palindrome
- HDU-4731-Minimum palindrome
- HDU 4731 Minimum palindrome
- HDU 4731 Minimum Palindrome
- HDU 4731 Minimum palindrome
- 2012成都赛区网络赛 hdu4292
- 2013网络赛成都赛区1003
- 2013网络赛成都赛区1010
- 2013年ACM网络赛成都赛区
- html字体颜色设置
- 口令管理
- 用ndk-stack分析应用native程序异常crash
- hdu 4737 A Bit Fun
- c++设计模式--对象适配器模式
- hdu 4731 Minimum palindrome(网络赛 成都赛区)
- Spring MVC 3.0 with STS Tutorial – Part I
- UbuntuServer添加软件源列表
- 我们约会吧
- Ubuntu下“E: 无法获得锁 /var/lib/apt/lists/lock - open (11: 资源暂时不可用)”的解决办法
- 重要的算法
- Cocos2dx 2.1.5 孤狼优化整合版V1.0(32位)
- 网页打开自动全屏
- HDU 1561 The more, The Better 依赖背包+树形DP