2013 ACM/ICPC Asia Regional Chengdu Online 1004 Minimum palindrome
来源:互联网 发布:监控画面 分析软件 编辑:程序博客网 时间:2024/06/05 15:57
Minimum palindrome
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 586 Accepted Submission(s): 110
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
2
2 2
2 3
Sample Output
Case #1: ab
Case #2: aab
3个及3个以上字母就可以不构成回文串,2个字母的打表找规律
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 int main() 8 { 9 int T;10 int cas=1;11 scanf("%d",&T);12 while(T--)13 {14 int n,m;15 scanf("%d%d",&n,&m);16 printf("Case #%d: ",cas++);17 if(n==1)18 {19 while(m--)20 putchar('a');21 putchar(10);22 continue;23 }24 if(n==2)25 {26 if(m<=8)27 {28 switch(m)29 {30 case 1:31 printf("a\n"); break;32 case 2:33 printf("ab\n"); break;34 case 3:35 printf("aab\n"); break;36 case 4:37 printf("aabb\n"); break;38 case 5:39 printf("aaaba\n"); break;40 case 6:41 printf("aaabab\n"); break;42 case 7:43 printf("aaababb\n"); break;44 case 8:45 printf("aaababbb\n"); break;46 }47 continue ;48 }49 else50 {51 printf("aaaababb");52 m-=8;53 int l=m/6;54 for(int i=0;i<l;i++)55 {56 printf("aababb");57 }58 l=m%6;59 switch(l)60 {61 case 1:62 printf("a\n"); break;63 case 2:64 printf("aa\n"); break;65 case 3:66 printf("aaa\n"); break;67 case 4:68 printf("aaaa\n"); break;69 case 5:70 printf("aabab\n"); break;71 }72 }73 }74 else75 {76 for(int i=0;i<m;i++)77 {78 putchar('a'+(i)%3);79 }80 putchar(10);81 }82 }83 84 return 0;85 }
0 0
- 2013 ACM/ICPC Asia Regional Chengdu Online 1004 Minimum palindrome
- hdu 4731 Minimum palindrome 找规律 (2013 ACM/ICPC Asia Regional Chengdu Online 1004)
- HDU 4731 Minimum palindrome 找规律 (2013 ACM/ICPC Asia Regional Chengdu Online 1004)
- hdu 4731 Minimum palindrome 找规律 (2013 ACM/ICPC Asia Regional Chengdu Online 1004)
- 2013 ACM/ICPC Asia Regional Chengdu Online HDU 4731 Minimum palindrome(规律)
- 2013 ACM/ICPC Asia Regional Chengdu Online
- 2013 ACM/ICPC Asia Regional Chengdu Online
- 2013 ACM/ICPC Asia Regional Chengdu Online
- 2013 ACM/ICPC Asia Regional Chengdu Online 个人总结
- 2013 ACM/ICPC Asia Regional Chengdu Online---1003
- 2012 ACM/ICPC Asia Regional Chengdu Online-hdu 4288
- 2012 ACM/ICPC Asia Regional Chengdu Online-hdu-4289
- 2012 ACM/ICPC Asia Regional Chengdu Online(hdu4291)
- 2012 ACM/ICPC Asia Regional Chengdu Online(hdu4292)
- hdu 4737 A Bit Fun 数列(2013 ACM/ICPC Asia Regional Chengdu Online 1010)
- 2013 ACM/ICPC Asia Regional Chengdu Online//HDU4730/HDU4731/HDU4734/HDU4737
- hdu 4734 F(x) 数位dp (2013 ACM/ICPC Asia Regional Chengdu Online 1007)
- 2013 ACM/ICPC Asia Regional Chengdu Online&hdu4735Little Wish~ lyrical step~(DLX解重复覆盖)
- 我看TechEd 2012之App时代降临
- 古城钟楼微博:葡萄城程序员演练技术的产物
- Asp.Net MVC4入门指南(5):从控制器访问数据模型
- Asp.Net MVC4入门指南(6):验证编辑方法和编辑视图
- WinRT开发语言的功能和效率
- 2013 ACM/ICPC Asia Regional Chengdu Online 1004 Minimum palindrome
- Asp.Net MVC4入门指南(7):给电影表和模型添加新字段
- HDOJ 4731 Minimum palindrome
- Asp.Net MVC4入门指南(8):给数据模型添加校验器
- POJ 1836 Alignment
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- POJ 3267 The Cow Lexicon
- Asp.Net MVC4入门指南(9):查询详细信息和删除记录
- DataGuard小结--1