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/Others)
Total Submission(s): 586 Accepted Submission(s): 110
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.
For each test case, there is a single line with two integers M and N, as described above.(1 <= M <= 26, 1 <= N <= 105)
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int main()
{
int T;
int cas=;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d%d",&n,&m);
printf("Case #%d: ",cas++);
if(n==)
{
while(m--)
putchar('a');
putchar();
continue;
}
if(n==)
{
if(m<=)
{
switch(m)
{
case :
printf("a\n"); break;
case :
printf("ab\n"); break;
case :
printf("aab\n"); break;
case :
printf("aabb\n"); break;
case :
printf("aaaba\n"); break;
case :
printf("aaabab\n"); break;
case :
printf("aaababb\n"); break;
case :
printf("aaababbb\n"); break;
}
continue ;
}
else
{
printf("aaaababb");
m-=;
int l=m/;
for(int i=;i<l;i++)
{
printf("aababb");
}
l=m%;
switch(l)
{
case :
printf("a\n"); break;
case :
printf("aa\n"); break;
case :
printf("aaa\n"); break;
case :
printf("aaaa\n"); break;
case :
printf("aabab\n"); break;
}
}
}
else
{
for(int i=;i<m;i++)
{
putchar('a'+(i)%);
}
putchar();
}
} return ;
}
2013 ACM/ICPC Asia Regional Chengdu Online 1004 Minimum palindrome的更多相关文章
- 2013 ACM/ICPC Asia Regional Chengdu Online hdu4731 Minimum palindrome
Minimum palindrome Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 2013 ACM/ICPC Asia Regional Chengdu Online---1003
哈哈哈 #include <iostream> #include <cstring> #include <string> #include <cstdio&g ...
- hdu 4751 Divide Groups bfs (2013 ACM/ICPC Asia Regional Nanjing Online 1004)
SDUST的训练赛 当时死磕这个水题3个小时,也无心去搞其他的 按照题意,转换成无向图,预处理去掉单向的边,然后判断剩下的图能否构成两个无向完全图(ps一个完全图也行或是一个完全图+一个孤点) 代码是 ...
- HDU4734——2013 ACM/ICPC Asia Regional Chengdu Online
今天做的比赛,和队友都有轻微被虐的赶脚. 诶,我做的题就是这个题目了. 题目描述就是对于一个十进制数数位上的每一位当做一个二进制位来求出这个数,这个定义为G(x). 题目给定你A和B,求在0-B范围内 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 文本模板转换工具包和 ASP.NET MVC
http://msdn.microsoft.com/zh-sg/magazine/ee291528.aspx
- Jenkins进阶系列之——15Maven获取Jenkins的Subversion的版本号
各位小伙伴们在工作中总是会碰到各种各样的奇葩需求,今天给大家说说Maven怎么在Jenkins中获取Subversion的版本号. Jenkins自己的环境变量中包含了很多有用的的参数,详情查看:ht ...
- Chrome扩展开发(Gmail附件管理助手)系列之〇——概述
目录: 0.Chrome扩展开发(Gmail附件管理助手)系列之〇——概述 1.Chrome扩展开发之一——Chrome扩展的文件结构 2.Chrome扩展开发之二——Chrome扩展中脚本的运行机制 ...
- Django实际站点项目开发经验谈
开发了两个月的Django站点正式上线了,看着网站从无到有,从前端到后台,从本地开发到环境部署,一点一滴的堆砌成型,着实带给我不小的乐趣. Django站点介绍: 开发环境:阿里云服务器centos6 ...
- EF实体框架之CodeFirst七
前面的6篇博客基本把Code First学习的差不多了,今天这篇学习下code first中的并发控制和事务,基本也快学完了,顶多就差数据迁移. 在数据库中也是有锁和事务的概念,在C#中也是存在,当然 ...
- Unity Networking API文档翻译(二):The High Level API
高级API (HLAPI) 是用来提供给Unity 创建多人在线游戏的组件.它是在底层传输层的基础上构建的, 对多人在线游戏提供了很多通用的功能.当传输层支持各种网络拓扑结构的时候,HLAPI是一个功 ...
- 线段树好题(2004集训队林涛PPT中的3题)
1.snake:主要是要意识到全局的可能连法只有一种= =(略坑,题目的最小长度是唬人的……),所以关键就是能否构造出符合题意的图,可以考虑搜索解决,搜出一个就OK了,但是会发现那些满足条件中线段在非 ...
- DOM(二)使用DOM
在了解DOM(文本对象模型)的框架和节点后,最重要的是使用这些节点处理html网页 对于一个DOM节点node,都有一系列的属性和方法可以使用.常用的有下表. 完善:http://www.w3scho ...
- java多线程-CyclicBarrier
介绍 一个同步辅助类,它允许一组线程互相等待,直到到达某个公共屏障点 (common barrier point).在涉及一组固定大小的线程的程序中,这些线程必须不时地互相等待,此时 CyclicBa ...
- c++ 中 delete p与 delete []p的区别
#include <cstdio> class A{private: int i;public: ~A() { printf("hi"); }};void d(A *) ...