题目大意:用m个字母组成一个长度为N的字符串,使得最长的回文子串 的长度最小。 并且要求字典序最小。

思路:分类模拟。

当M为1 的时候就直接输出N个A

当M大于2的时候就循环ABC

当M等于2的时候

先枚举出当N<9 的情况,因为此时可以用最长串长度为 3 的基础上得到。

而当N>9的时候。

其实就是 aababb 为循环节的一个循环。但是此时是建立在最长串为4的基础上得到

但是有另外的情况就是

m==2 n%6<=4的时候最后面就不是循环循环节了。

例如:

m=2 n=10

aababbaaaa.

而不是

aababbaaba.

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set> using namespace std; #ifdef WIN
typedef __int64 LL;
#define iform "%I64d"
#define oform "%I64d\n"
#else
typedef long long LL;
#define iform "%lld"
#define oform "%lld\n"
#endif const double eps = 10e-9;
#define SI(a) scanf("%d", &(a))
#define SDI(a, b) scanf("%d%d", &(a), &(b))
#define SUI(a) scanf("%ud", &(a))
#define S64I(a) scanf(iform, &(a))
#define SS(a) scanf("%s", (a))
#define SC(a) scanf("%c", &(a))
#define PI(a) printf("%d\n", a)
#define P64I(a) printf(oform, a)
#define Max(a, b) (a > b ? a : b)
#define Min(a, b) (a < b ? a : b)
#define MSET(a, b) (memset(a, b, sizeof(a)))
#define Mid(L, R) (L + (R - L)/2)
#define ABS(a) (a > 0 ? a : -a)
#define REP(i, n) for(int i=0; i < (n); i++)
#define FOR(i, a, n) for(int i=(a); i <= (n); i++)
typedef unsigned int UINT; const char tab[8][20] = {
"a", "ab", "aab", "aabb", "aaaba", "aaabab", "aaababb", "aaababbb"}; int main() {
int T; SI(T);
FOR(kase, 1, T) {
int m, n;
SDI(m, n); printf("Case #%d: ", kase); if(m>2) {
//int tn = n - m + 3;
int a = n / 3;
int b = n % 3;
REP(i, a) printf("abc");
REP(i, b) printf("%c", 'a'+i);
//REP(i, m-3) printf("%c", 'd'+i);
printf("\n");
} else if(m == 1) {
REP(i, n) putchar('a');
printf("\n");
} else {
if(n < 9) {
printf("%s\n", tab[n-1]);
} else {
char t[] = "babbaa";
printf("aaaa");
int a = (n-4) / 6;
int b = (n-4) % 6;
REP(i, a) printf("babbaa");
if(b <= 2) REP(i, b) putchar('a');
else REP(i, b) putchar(t[i]);
printf("\n");
}
}
} return 0;
}

2013 成都网络赛 1004 Minimum palindrome的更多相关文章

  1. HDU 4731 Minimum palindrome (2013成都网络赛,找规律构造)

    Minimum palindrome Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  3. HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)

    Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  4. HDU 4741 Save Labman No.004 (2013杭州网络赛1004题,求三维空间异面直线的距离及最近点)

    Save Labman No.004 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  5. 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 ...

  6. HDU 4734 F(x) (2013成都网络赛,数位DP)

    F(x) Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  7. HDU 4733 G(x) (2013成都网络赛,递推)

    G(x) Time Limit: 2000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  8. 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) ...

  9. 2013成都网络赛 J A Bit Fun(水题)

    A Bit Fun Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. Foundation 框架 归档

    一.使用XML属性列表归档 此方法适用于NSString.NSDictionary.NSarray.NSDate.NSnumber,其中atomically参数表示先将字典写入临时备份文件,成功之后, ...

  2. Problem D: Integer Inquiry

    Problem D: Integer InquiryTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 41 Solved: 12[Submit][Status ...

  3. ASP.NET jQuery 随笔 显示RadioButtonList成员选中的内容和值

    通过jQuery来获取RadioButtonList成员内容. <%@ Page Language="C#" AutoEventWireup="true" ...

  4. bootstrap读书笔记

    引入bootstrap.js或单个插件的js文件 若引入单个插件的js文件,注意插件之间的依赖关系 data属性api data属性的api很方便,但我们也可以选择关闭这个功能:$(document) ...

  5. config.json ajenti

    {    "users": {        "root": {            "configs": {               ...

  6. LeetCode——Combinations

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...

  7. SQL Server 性能优化

    今天有位网友找我给他原有的系统数据库优化下查询速度,个人总结了几点对sqlserver的优化 1.Sql查询语句的优化,如:能使用外连接查询出来的尽量别用内连接...,这些个就不废话,如果我使用这个给 ...

  8. No.2小白的HTML+CSS心得篇

    今天要强调的重点是分析把握好HTML标签的两个方面: 1.标签的用途(用途指的是用来干什么,有什么作用)在专业术语叫作 语义化. 举个列子:<br/> 换行的作用 见了它就明白它的语义就是 ...

  9. C# inherit

    Case:class A has a construct. class B is inherit from class A and B also has a construct. What's the ...

  10. input autocomplete 下拉提示+支持中文

    js 代码: $.getJSON("/Foreign/Getforeign_routeEndPoint", function (data) {            $(" ...