博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2013 ACM/ICPC Asia Regional Chengdu Online hdu4731 Minimum palindrome
阅读量:7105 次
发布时间:2019-06-28

本文共 2013 字,大约阅读时间需要 6 分钟。

Minimum palindrome

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 309    Accepted Submission(s): 150

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=1时,很简单,输出N个a就行了;

当M=2时,前8个没规律,后面的有规律的;

当M=3时,”abc“这个字符串一直排到N个就行了;

代码:

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 8 using namespace std; 9 10 int main()11 {12 int t,i;13 cin>>t;14 int k=1;15 char a[200];16 while(t--)17 {18 int n,m;19 cin>>n>>m;20 cout<<"Case #"<
<<": ";21 if(n==1)22 {23 for(i=0; i
2)28 {29 for(i=0; i
View Code

 

 

 

转载于:https://www.cnblogs.com/ERKE/p/3323238.html

你可能感兴趣的文章
http请求状态码和请求信息的含义
查看>>
关于假设检验
查看>>
MapReduce原理(分布式计算模型)----------总结
查看>>
Linux学习笔记(九)--命令学习(文件与目录查看)
查看>>
2013最新Ghost Windows 7硬盘安装法详细(图文)教程
查看>>
centos6.5 安装mysql5.6多实例(多配置文件)
查看>>
Redis配置文件主要功能说明
查看>>
为什么要"去IOE"
查看>>
ubuntu 12.04安装mongodb+eclipse erlang plugin+erlang runtime
查看>>
arm-linux-gcc4.4.3编译s3c2410平台linux内核
查看>>
gitlab服务器
查看>>
我的友情链接
查看>>
Case_Compressed Mode_Background
查看>>
python 利用pexpect进行多机远程命令执行
查看>>
Python学习系列 (第一章):Python 的简介
查看>>
【转载】addShutdownHook的用处
查看>>
CSS3学习3----举例
查看>>
一个可以检测网络内主机类型的脚本
查看>>
利用Zabbix监控Lync的实时在线人数
查看>>
使用strace+pstack利器分析程序性能
查看>>