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

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

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

代码:

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h> using namespace std; int main()
{
int t,i;
cin>>t;
int k=;
char a[];
while(t--)
{
int n,m;
cin>>n>>m;
cout<<"Case #"<<k++<<": ";
if(n==)
{
for(i=; i<m; i++)
cout<<'a';
cout<<endl;
}
else if(n>)
{
for(i=; i<m; i++)
cout<<(char)('a'+i%);
cout<<endl;
}
else
{
char b[][]= {"a",
"ab",
"aab",
"aabb",
"aaaba",
"aaabab",
"aaababb",
"aaababbb"
};
if(m<=)
{
cout<<b[m-]<<endl;
}
else
{
cout<<"aa";
m--;
m--;
for(i=;i<m/;i++)
cout<<"aababb";
if(m%==)
cout<<'a';
else
if(m%==)
cout<<"aa";
else
if(m%==)
cout<<"aaa";
if(m%==)
cout<<"aaaa";
if(m%==)
cout<<"aabab";
cout<<endl;
}
}
}
}

2013 ACM/ICPC Asia Regional Chengdu Online hdu4731 Minimum palindrome的更多相关文章

  1. 2013 ACM/ICPC Asia Regional Chengdu Online 1004 Minimum palindrome

    Minimum palindrome Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. 2013 ACM/ICPC Asia Regional Chengdu Online---1003

    哈哈哈 #include <iostream> #include <cstring> #include <string> #include <cstdio&g ...

  3. HDU4734——2013 ACM/ICPC Asia Regional Chengdu Online

    今天做的比赛,和队友都有轻微被虐的赶脚. 诶,我做的题就是这个题目了. 题目描述就是对于一个十进制数数位上的每一位当做一个二进制位来求出这个数,这个定义为G(x). 题目给定你A和B,求在0-B范围内 ...

  4. HDU 4729 An Easy Problem for Elfness(主席树)(2013 ACM/ICPC Asia Regional Chengdu Online)

    Problem Description Pfctgeorge is totally a tall rich and handsome guy. He plans to build a huge wat ...

  5. HDU 4735 Little Wish~ lyrical step~(DLX搜索)(2013 ACM/ICPC Asia Regional Chengdu Online)

    Description N children are living in a tree with exactly N nodes, on each node there lies either a b ...

  6. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  7. hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...

  8. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

  9. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

随机推荐

  1. webservice时间类型XMLGregorianCalendar和Date的转换

    //ISO日期转换为UTC日期 public XMLGregorianCalendar xmlToDate(Date date){ GregorianCalendar cal = new Gregor ...

  2. jmeter3.2 创建webservice 测试

    1.创建测试计划 templates→select Template→Building a SOAP WebService Test Plan 2.修改HTTP Request Defaults中的参 ...

  3. ZXing生成条形码、二维码、带logo二维码

    采用的是开源的ZXing,Maven配置如下,jar包下载地址,自己选择版本下载,顺便推荐下Maven Repository <!-- https://mvnrepository.com/art ...

  4. 2017 ACM-ICPC(乌鲁木齐赛区)网络赛 H.Skiing 拓扑排序+最长路

    H.Skiing In this winter holiday, Bob has a plan for skiing at the mountain resort. This ski resort h ...

  5. main方法快速编辑日历

    public static void main(String[] args) { Scanner input=new Scanner (System.in); System.out.println(& ...

  6. nginx小问题

    配置nginx与ftp图片服务器:安装后,要在/usr/local/nginx/conf/nginx.conf里面的server中(带有localhost的那一块)修改为location \ {roo ...

  7. mysql初学,mysql修改,mysql查找,mysql删除,mysql基本命令

    Mysql 下载地址https://dev.mysql.com/downloads/mysql/ 1.连接Mysql格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYS ...

  8. Java 多线程(四) 多线程访问成员变量与局部变量

    先看一个程序例子: public class HelloThreadTest { public static void main(String[] args) { HelloThread r = ne ...

  9. yyt

    红颜迤逦隔云梯, 相思萦系解花语. 我有相思千般意, 百磨不灭铭肝肠.

  10. 【集美大学1411_助教博客】团队作业5——测试与发布(Alpha版本)

    同学们好像都进入了状态,任务都完成的不错,测试与发布是一个软件的非常重要的环节,每年双11前夕是阿里巴巴加班最严重的时期,这是因为他们在不断的测试,因为他们不想在双11到来之时有任何差池.所以无论你的 ...