D - Minimum palindrome----(2015 summer training #9)
2015-08-14 13:17
337 查看
D - Minimum palindrome
时限:1000MS 内存:32768KB 64位IO格式:%I64d
& %I64u
问题描述
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.
输入
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)
输出
For test case X, output "Case #X: " first, then output the best password.
样例输入
样例输出
分析:有意思的一道题,开始并没有发现是找规律的题,仔细一想其实也是能想出来的。
CODE:
时限:1000MS 内存:32768KB 64位IO格式:%I64d
& %I64u
问题描述
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.
输入
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)
输出
For test case X, output "Case #X: " first, then output the best password.
样例输入
2 2 2 2 3
样例输出
Case #1: ab Case #2: aab
分析:有意思的一道题,开始并没有发现是找规律的题,仔细一想其实也是能想出来的。
CODE:
#include <iostream> using namespace std; int main() { int t,cases=0; cin>>t; while(t--){ int n,m; cin>>m>>n; cases++; cout<<"Case #"<<cases<<": "; if(m==1){ while(n--) cout<<'a'; } else if(m>2){ for(int i=0;i<n;i++) cout<<char('a'+i%3); } else{ switch(n){ case 1: cout<<'a'; break; case 2: cout<<"ab"; break; case 3: cout<<"aab"; break; case 4: cout<<"aabb"; break; case 5: cout<<"aaaba"; break; case 6: cout<<"aaabab"; break; case 7: cout<<"aaababb"; break; case 8: cout<<"aaababbb"; break; default:{ cout<<"aa"; for(int i=0;i<(n-2)/6;i++) cout<<"aababb"; int mod=(n-2)%6; if(mod<5){ while(mod--) cout<<'a'; } else cout<<"aaaab"; } } } cout<<endl; } return 0; }
相关文章推荐
- C - We Love MOE Girls-----(2015 summer training #9)
- B - Median-----(2015 summer training #8(Qualifying))
- Could not connect to '10.7.100.182' (port 22): Connection failed
- HIT 2060 Fibonacci Problem Again
- LeetCode Factorial Trailing Zeroes
- LeetCode Factorial Trailing Zeroes
- epoll_create, epoll_ctl和epoll_wait
- 2015 Multi-University Training Contest 2(hdu 5300 - hdu 5309)
- Clock Skew , Clock Uncertainty和 Period
- libvirtError: no connection driver available for qemu:///system 解决办法
- 2015 Multi-University Training Contest 8 hdu 5384 Danganronpa
- tools:context=".MainActivity的作用
- 使用Grails快速开发Web应用程序
- 构建您的第一个Grails 应用程序
- 2015 Multi-University Training Contest 1(hdu 5288 - hdu 5299)
- hdu1021Fibonacci Again找规律
- PS和AI软件区别
- HDU - 3394 Railway(连通分量+环)
- qmail 相关问题
- 智能改变未来TurboMail邮件系统招商新计划