HDU 4731 Minimum palindrome (2013成都网络赛,找规律构造)
Minimum palindrome
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 260 Accepted Submission(s): 127
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)
2 2
2 3
Case #2: aab
找规律。
当m=1时,直接输出n个a
当m>=3时,输出abcabcabc....
当m=2时,先暴力打出1~20的表。然后找规律发现循环
/* ***********************************************
Author :kuangbin
Created Time :2013/9/14 星期六 13:21:24
File Name :2013成都网络赛\1004.cpp
************************************************ */ #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; char str[];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
int m,n;
int iCase = ;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&m,&n);
iCase++;
printf("Case #%d: ",iCase);
if(m == )
{
for(int i = ;i < n;i++)printf("a");
printf("\n");
continue;
}
if(m >= )
{
int index = ;
for(int i = ;i < n;i++)
{
printf("%c",index + 'a');
index = (index + )%;
}
printf("\n");
continue;
}
if(n == )printf("a");
else if(n == )printf("ab");
else if(n == )printf("aab");
else if(n == )printf("aabb");
else if(n == )printf("aaaba");
else if(n == )printf("aaabab");
else if(n == )printf("aaababb");
else if(n == )printf("aaababbb");
else if(n == )printf("aaaababba");
else
{
printf("aaaa");
n -= ;
while(n >= )
{
printf("babbaa");
n -= ;
}
if(n == )printf("a");
else if(n == )printf("aa");
else if(n == )printf("bab");
else if(n == )printf("babb");
else if(n == )printf("babba");
}
printf("\n");
}
return ;
}
HDU 4731 Minimum palindrome (2013成都网络赛,找规律构造)的更多相关文章
- HDU 4733 G(x) (2013成都网络赛,递推)
G(x) Time Limit: 2000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 4731 Minimum palindrome 2013 ACM/ICPC 成都网络赛
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4731 题解:规律题,我们可以发现当m大于等于3时,abcabcabc……这个串的回文为1,并且字典数最小 ...
- HDU 4737 A Bit Fun (2013成都网络赛)
A Bit Fun Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 4734 F(x) (2013成都网络赛,数位DP)
F(x) Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 4730 We Love MOE Girls (2013成都网络赛,签到水题)
We Love MOE Girls Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4768 Flyer (2013长春网络赛1010题,二分)
Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4747 Mex (2013杭州网络赛1010题,线段树)
Mex Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submis ...
- HDU 4731 Minimum palindrome 打表找规律
http://acm.hdu.edu.cn/showproblem.php?pid=4731 就做了两道...也就这题还能发博客了...虽然也是水题 先暴力DFS打表找规律...发现4个一组循环节.. ...
- hdu 4731 2013成都赛区网络赛 找规律
题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举
随机推荐
- assign()函数
tf中assign()函数可用于对变量进行更新包括变量的value和shape. 涉及以下函数: tf.assign(ref, value, validate_shape = None, use_lo ...
- 关于caffe的安装问题
在caffe的安装过程中,出现 /usr/bin/ld: cannot find -lcblas /usr/bin/ld: cannot find -latlas的问题 这时解决方案为http://s ...
- 洛谷 P5206: bzoj 5475: LOJ 2983: [WC2019] 数树
一道技巧性非常强的计数题,历年WC出得最好(同时可能是比较简单)的题目之一. 题目传送门:洛谷P5206. 题意简述: 给定 \(n, y\). 一张图有 \(|V| = n\) 个点.对于两棵树 \ ...
- Convert Expression to Reverse Polish Notation
Given an expression string array, return the Reverse Polish notation of this expression. (remove the ...
- centos7系统下安装配置jdk、tomcat教程
JDK安装与配置 1.下载linux版本的jdk,我下的版本是jdk6.0,下载rpm版本的. 可通过百度搜索文件名:jdk-6u45-linux-x64-rpm.bin下载 也可通过oracle官网 ...
- 全键盘操作Windows
计算机机用户在使用计算机的时候,是用键盘多一点?还是用鼠标多一点?如果是专业打字员,应该会说他使用键盘多一点,除此之外,多数人都会告诉你,他已经离不开鼠标了,没有鼠标,就不会操作电脑. 如果某一天 ...
- js replace,正则截取字符串内容
1.js replace替换,使用 http://www.jb51.net/article/43949.htm 顺便记录一下 e.g. js获取sql中的可替换参数$id,$name."SE ...
- MVC母板页传递数据
问题:判断Session 失败 结果: if (Session[SessionKey.AccountInfo] != null) { ViewData["AdminUser"] = ...
- 镜像文件挂载及本地yum搭建
环境:centos7.2 背景:企业内网不能上网,需安装软件以及软件之间的依赖问题 解决方案:下载和企业内网服务器相同版本的centos7.2镜像文件完整版(不是最小化的iso) 挂载镜像文件 1.上 ...
- stm32+ESP8266AT指令详细说明
最近公司团队的项目用到ESP8266,使用的是stm32c8t6芯片,软件使用MDK,于是写下调试过程中的一些注意点.具体代码和涉及思路不能外泄,这里只给出我们调试过程中的注意的方面. 关于ESP82 ...