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. [2012-05-31]awk记录分割符RS

    $awk -v RS= '{print $1}' test RS 默认值为\n 换行符. 此处设置RS= 等效于 RS="" 代表一个空行 (若理解有误请指正,在以下例子中符合) ...

  2. LVDS/RGB转EDP稳定方案----NCS8801S

    目前山寨平板市场已经进入白热化,同质化的竞争.厂商的利润被压得非常的薄.一味的价格战肯定会带来行业洗牌.差异化是许多厂商的选择,而其中一条重要的路子,就是采用高分辨率的down-grade屏.如苹果的 ...

  3. Varnish后端主机的健康状态检查

    author:JevonWei 版权声明:原创作品 配置后端主机的Health Check 环境 Varnish 192.168.198.139 图片服务端 192.168.198.120 程序服务端 ...

  4. Zookeeper的安装的配置

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt192 安装和配置详解 本文介绍的 Zookeeper 是以 3.2.2 这个 ...

  5. 【集美大学1411_助教博客】个人作业2——英语学习APP案例分析 成绩

    个人作业2--英语学习APP案例分析,截止发稿时间全班31人,提交31,未提交0人.有一名同学已经写了作业但忘记提交了,这次给分了,但下不为例.由于助教这周有点忙,所以点评得非常不及时,请同学们见谅. ...

  6. 201521123077 《Java程序设计》第7周学习总结

    1. 本周学习总结 (图片来自网络) 可以看到,java的容器很多,这里讲一下这周经常用到的 ArrayList:用数组形式保存数据的容器,随机访问比较快,但是插入删除操作都比较耗时,会自动调整内部数 ...

  7. 201521123026 《java程序设计》 第九周学习总结

    1. 本章学习总结 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 Q1.常用异常 题目5-1 1.1 截图你的提交结果(出现学号) PTA提交结果: 运行结果截图: 1.2 ...

  8. PHP字符串常用操作

    常用操作有: PHP中有两个内建的函数:count() 和sizeof(),可以实现得到数组的长度 count($sttr);数组长度 字符串长度:strlen(string $a); 判断是否相同, ...

  9. 巧用 BootStrap --- 栅格系统(布局)轻松搞定网页响应式布局!

    摘要:Bootstrap 为我们提供了一套响应式.移动设备优先的流式栅格系统,合理的使用栅格系统将会使得网站页面布局变得更加简单,在设置了媒体查询之后,响应式网站也无需再单独写了.接下来我以Boots ...

  10. CSS3滤镜(filter--CSS3技术

    filter 属性定义了元素(通常是<img>)的可视效果,例如图片的模糊.饱和度.灰度等……个人感觉功能很强大 1.filter的语法 filter: none | blur() | b ...