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. 认清Javascript的地位并编写合理的Javascript代码

    作为前端程序员,一定要认清javascript的地位,不要被它乱七八糟的特点所迷惑.JavaScript主要是用来操控和重新调整DOM,通过修改DOM结构,从而达到修改页面效果的目的. 要用这个中心思 ...

  2. 在windows中,使用SSH登录VMware ubuntu linux虚拟机

    测试环境 主机:window7 sp1 64位 专业版 虚拟机:VMware workstation 12 player 虚拟机操作系统: ubuntu 16.4 目标:在ubuntu下运行SSH服务 ...

  3. IT行业有前景么?一个10年行内人的6点看法

    本人毕业快11年了. 大学读的建筑专业,却在IT行业干了10年. 真心来讲,我非常感谢好兄弟老唐,是他在我迷茫的那两年,领着我踏入了IT行业,也找到了自己的兴趣爱好. 这些年我经常在知乎.博客等地方发 ...

  4. 201521123075 《Java程序设计》第5周学习总结

    1. 本周学习总结 2. 书面作业 作业参考文件下载 1 .代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过?哪句会出现错误?试改正该错误.并分 ...

  5. 201521123109《java程序设计》第五周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 1.2 可选:使用常规方法总结其他上课内容. 2. 书面作业 作业参考文件下载 1.代码阅读:Child压缩包内源代码 1.1 ...

  6. 201521123122《Java程序设计》第1周学习总结

    1. 本周学习总结 因为寒假里也没有好好预习java,第一周上课还是有点懵逼. ①.了解了JVM,JRE,JDK的区别,能够熟练安装JDK. ②.编了我人生中的第一个java程序"hello ...

  7. 201521123105 第10周Java学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. 2. 书面作业 本次PTA作业题集异常.多线程 1.finally 题目4-21.1 截图你的提交结果(出现 ...

  8. 201521123029《Java程序设计》第十二周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...

  9. 在控制台显示“Hello World”

    //作者:江骆 //功能:在控制台显示"Hello World" //日期:2017.7.19 public class helloworld   //public 表示公共类,一 ...

  10. [js高手之路]Node.js模板引擎教程-jade速学与实战3-mixin

    强大的mixin mixin类似于函数的功能,可以达到模块复用的效果 mixin show: 定义一个类似函数的功能,名字叫show,里面的就是他的内容 +show: 调用show,每调用一次执行一次 ...