HDOJ 4731 Minimum palindrome
来源:互联网 发布:监控画面 分析软件 编辑:程序博客网 时间:2024/06/06 03:28
Minimum palindrome
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 54 Accepted Submission(s): 18
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.
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)
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
2 2
2 3
Sample Output
Case #1: ab
Case #2: aab
Case #2: aab
Source
2013 ACM/ICPC Asia Regional Chengdu Online
Recommend
liuyiding
3个及3个以上字母就可以不构成回文串,2个字母的打表找规律
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int T;
int cas=1;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d%d",&n,&m);
printf("Case #%d: ",cas++);
if(n==1)
{
while(m--)
putchar('a');
putchar(10);
continue;
}
if(n==2)
{
if(m<=8)
{
switch(m)
{
case 1:
printf("a\n"); break;
case 2:
printf("ab\n"); break;
case 3:
printf("aab\n"); break;
case 4:
printf("aabb\n"); break;
case 5:
printf("aaaba\n"); break;
case 6:
printf("aaabab\n"); break;
case 7:
printf("aaababb\n"); break;
case 8:
printf("aaababbb\n"); break;
}
continue ;
}
else
{
printf("aaaababb");
m-=8;
int l=m/6;
for(int i=0;i<l;i++)
{
printf("aababb");
}
l=m%6;
switch(l)
{
case 1:
printf("a\n"); break;
case 2:
printf("aa\n"); break;
case 3:
printf("aaa\n"); break;
case 4:
printf("aaaa\n"); break;
case 5:
printf("aabab\n"); break;
}
}
}
else
{
for(int i=0;i<m;i++)
{
putchar('a'+(i)%3);
}
putchar(10);
}
}
return 0;
}
* This source code was highlighted by YcdoiT. ( style: Codeblocks )#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int T;
int cas=1;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d%d",&n,&m);
printf("Case #%d: ",cas++);
if(n==1)
{
while(m--)
putchar('a');
putchar(10);
continue;
}
if(n==2)
{
if(m<=8)
{
switch(m)
{
case 1:
printf("a\n"); break;
case 2:
printf("ab\n"); break;
case 3:
printf("aab\n"); break;
case 4:
printf("aabb\n"); break;
case 5:
printf("aaaba\n"); break;
case 6:
printf("aaabab\n"); break;
case 7:
printf("aaababb\n"); break;
case 8:
printf("aaababbb\n"); break;
}
continue ;
}
else
{
printf("aaaababb");
m-=8;
int l=m/6;
for(int i=0;i<l;i++)
{
printf("aababb");
}
l=m%6;
switch(l)
{
case 1:
printf("a\n"); break;
case 2:
printf("aa\n"); break;
case 3:
printf("aaa\n"); break;
case 4:
printf("aaaa\n"); break;
case 5:
printf("aabab\n"); break;
}
}
}
else
{
for(int i=0;i<m;i++)
{
putchar('a'+(i)%3);
}
putchar(10);
}
}
return 0;
}
0 0
- HDOJ 4731 Minimum palindrome
- HDOJ 4731 - Minimum palindrome 找规律
- HDU: 4731 Minimum palindrome
- HDU-4731-Minimum palindrome
- HDU 4731 Minimum palindrome
- HDU 4731 Minimum Palindrome
- HDU 4731 Minimum palindrome
- hdu 4731 Minimum palindrome(构造)
- HDU 4731 Minimum palindrome 解题报告
- HDU - 4731 Minimum palindrome 找规律
- HDU 4731 Minimum palindrome(规律 构造)
- HDU 4731 Minimum palindrome+找规律技巧
- hdu 4731 Minimum palindrome(网络赛 成都赛区)
- hdu 4731 Minimum palindrome(暴力打表找规律)
- HDU 4731 Minimum palindrome 2013 ACM/ICPC 成都网络赛
- hdoj 1513 Palindrome
- HDOJ 4632: Palindrome subsequence
- HDOJ 4632 Palindrome subsequence
- Asp.Net MVC4入门指南(5):从控制器访问数据模型
- Asp.Net MVC4入门指南(6):验证编辑方法和编辑视图
- WinRT开发语言的功能和效率
- 2013 ACM/ICPC Asia Regional Chengdu Online 1004 Minimum palindrome
- Asp.Net MVC4入门指南(7):给电影表和模型添加新字段
- HDOJ 4731 Minimum palindrome
- Asp.Net MVC4入门指南(8):给数据模型添加校验器
- POJ 1836 Alignment
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- POJ 3267 The Cow Lexicon
- Asp.Net MVC4入门指南(9):查询详细信息和删除记录
- DataGuard小结--1
- POJ 1054 The Troublesome Frog
- Asp.Net MVC4入门指南(10):第三方控件Studio for ASP.NET Wijmo MVC4 工具应用
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
lamy safari
凌美笔尖
凌翔茜
凌莉
凌虚
凌越
星徒 凌越
凌越仙记 妹姒
凌轩
凌轩和宁惠芬
凌轩 2017款 1.6l 手动幸福型
凌迟
凌迟处死
石达开凌迟
凌迟图片
凌迟多少刀
凌迟女犯
洪宣娇凌迟真实照片
贾元春被凌迟处死
凌迟是什么意思
石达开被凌迟照片
清末女性凌迟老照片
凌迟什么意思
凌迟处死女犯人图片
凌迟陈玉成真实照片
刘瑾凌迟后还可以吃饭
凌迟处死的意思是什么意思
洪宣娇凌迟处死的过程
凌迟处死是什么意思
檀香刑女被凌迟的片段
石达开妻子被凌迟过程
太平军女将萧梅韵凌迟
凌途
xlv
途凌
凌途行车记录仪
双龙途凌
凌钢吧
凌钢
凌钢股票
凌钢股份重组