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. js事件汇总

    常用事件: 1.鼠标事件:onClick,onDblClick,onMouseDown,onMouseUp,onMouseOut,onMouseOver ·onClick:单击页面元素时发生,onDb ...

  2. vue非父子组件间通信

    有时候非父子关系的组件也需要通信.在简单的场景下,使用一个空的Vue实例作为中央事件总线: 有时候非父子关系的组件也需要通信.在简单的场景下,使用一个空的 Vue 实例作为中央事件总线: var bu ...

  3. 【Java数据结构学习笔记之二】Java数据结构与算法之队列(Queue)实现

      本篇是数据结构与算法的第三篇,本篇我们将来了解一下知识点: 队列的抽象数据类型 顺序队列的设计与实现 链式队列的设计与实现 队列应用的简单举例 优先队列的设置与实现双链表实现 队列的抽象数据类型 ...

  4. Python输入输出练习,运算练习,turtle初步练习

    Hello World! 简单交互(交互式,文件式)教材P19 radius=25 area=3.1415*radius*radius print(area) print('{:.2f}'.forma ...

  5. ★RFC标准库_目录链接

    RFC(Request For Comments)是一个国际标准化的数据库,记录了从计算机到互联网的海量标准协议.它是一个免费公开的IT标准文件分享平台,其内容也在不断增长,与时俱进.它与ISO等组织 ...

  6. 201521123008《Java程序设计》第二周实验总结

    本周学习总结 ① 数据类型,其中char是占用两个字节的内存空间,其他和以前学过的一样.除了十进制位,整型也可以用八进制或者十六进制表示.浮点型不精确. ②运算符,算术,赋值,逻辑,位运算. ③str ...

  7. 201521123056 《Java程序设计》第1周学习总结

    1. 本周学习总结 java语言结构简单,但功能齐全,同时能够在不同系统平台上编译,但编译的前提是系统要有安装JVM(即java虚拟机),JVM是java实现跨平台的最核心部分.本周还学习了JDK.J ...

  8. 201521123060《Java程序设计》第1周学习总结

    1. 本章学习总结 认识和了解了Java的发展进程: 了解了相关开发工具: 认识了JVM,JRE,JDK: 2. 书面作业 Q1.为什么java程序可以跨平台运行?执行java程序的步骤是什么?(请用 ...

  9. Python[小甲鱼-002用Python设计第一个游戏]

    –Code——————————————————————- print("----------第一个小游戏----------") temp = input("猜一下我现在 ...

  10. #黑客社会工程学攻防演练#[Chapter 1]

    1.1 什么是社会工程学 社会工程学(Social Engineering)是关于建立理论通过自然的.社会的和制度上的途径并特别强调根据现实的双向计划和设计经验来一步一步地解决各种社会问题.社会工程学 ...