http://acm.hdu.edu.cn/showproblem.php?pid=4731

就做了两道...也就这题还能发博客了...虽然也是水题

先暴力DFS打表找规律...发现4个一组循环节...尾部特殊判断....然后构造一下...

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int ss;
int f(const string& strs) {
string s("##");
for(string::const_iterator it = strs.begin(); it != strs.end(); ++it) {
s.push_back(*it);
s.push_back('#');
}
int len = s.length(), id = , mx = ;
vector<int> p(len, );
for(int i = ; i < len; ++i) {
p[i] = mx > i ? min(mx - i, p[*id-i]) : ;
while(s[i+p[i]] == s[i-p[i]]) {
++p[i];
}
if(i + p[i] > mx) {
mx = i + p[i];
id = i;
}
}
int start = , sublen = ;
for(int i = ; i < len; ++i) {
if(p[i] > sublen) {
sublen = p[i];
start = i;
}
}
return sublen - ;
}
int main(){
//pre();
int n,m;
int T;
cin>>T;
for(int t = ; t <= T ; t++){
scanf("%d%d",&m,&n);
printf("Case #%d: ",t);
if(m == ){
for(int i = ; i < n ; i++) printf("a");
}
else if(m >= ){
for(int i = ; i < n ; i++) {
if(i% == ) putchar('a');
if(i% == ) putchar('b');
if(i% == ) putchar('c');
}
}else if(m == ){
if(n == ) printf("a");
if(n == ) printf("ab");
if(n == ) printf("aab");
if(n == ) printf("aabb");
if(n == ) printf("aaaba");
if(n == ) printf("aaabab");
if(n == ) printf("aaababb");
if(n == ) printf("aaababbb");
if(n >= ){
string a = "aaaa";
for(int i = ; i < n ;){
if(i+<n) {
a+="babb";
i+=;
}
if(i+>=n) {
if(i+==n) a+="a";
if(i+==n) a+="aa";
if(i+==n) a+="aaa";
if(i+==n) a+="aaaa";
break;
}
if(i+<n) {
a+="aaba";
i+=;
}
if(i+>=n) {
if(i+==n) a+="b";
if(i+==n) a+="bb";
if(i+==n) a+="bba";
if(i+==n) a+="bbaa";
break;
}
if(i+<n) {
a+="bbaa";
i+=;
}
if(i+>=n) {
if(i+==n) a+="a";
if(i+==n) a+="aa";
if(i+==n) a+="bab";
if(i+==n) a+="babb";
break;
}
}
cout<<a;
}
}
putchar('\n');
}
return ;
}

HDU 4731 Minimum palindrome 打表找规律的更多相关文章

  1. HDU 3032 (SG打表找规律)

    题意: 有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 思路: 因为数的范围 ...

  2. 数学--数论--HDU - 6124 Euler theorem (打表找规律)

    HazelFan is given two positive integers a,b, and he wants to calculate amodb. But now he forgets the ...

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

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

  4. HDU 4731 Minimum palindrome (找规律)

    M=1:aaaaaaaa…… M=2:DFS+manacher, 暴出N=1~25的最优解,找规律.N<=8的时候直接输出,N>8时,头两个字母一定是aa,剩下的以aababb循环,最后剩 ...

  5. HDU 4731 Minimum palindrome 2013 ACM/ICPC 成都网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4731 题解:规律题,我们可以发现当m大于等于3时,abcabcabc……这个串的回文为1,并且字典数最小 ...

  6. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  7. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  8. HDU 5795 A Simple Nim(SG打表找规律)

    SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...

  9. HDU 4861 Couple doubi (数论 or 打表找规律)

    Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...

随机推荐

  1. UI Framework-1: Aura Focus and Activation

    Focus and Activation Focus and Activation are closely related.   Definitions Focused window - this i ...

  2. 洛谷1005 【NOIP2007】矩阵取数游戏

    问题描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n*m的矩阵,矩阵中的每个元素aij均为非负整数.游戏规则如下: 1.每次取数时须从每行各取走一个元素,共n个.m次后取完矩阵所有元素: 2. ...

  3. HDU-1789 Doing Homework again 贪心问题 有时间限制的最小化惩罚问题

    题目链接:https://cn.vjudge.net/problem/HDU-1789 题意 小明有一大堆作业没写,且做一个作业就要花一天时间 给出所有作业的时间限制,和不写作业后要扣的分数 问如何安 ...

  4. 【深度学习大讲堂】首期第一讲:人工智能的ABCDE 第二部分:简谈当前AI技术与发展趋势

    (完)

  5. MapReduce实现线性回归

    1. 软件版本号: Hadoop2.6.0(IDEA中源代码编译使用CDH5.7.3,相应Hadoop2.6.0),集群使用原生Hadoop2.6.4.JDK1.8,Intellij IDEA 14 ...

  6. modSecurity规则学习(八)——防止CC攻击

    modSecurity日志收集:在phase 5阶段处理. 由于CC攻击主要考虑对动态请求的防护,所以要排除静态资源的请求,或者自定义动态请求的后缀或者关键字做接口针对性的防护. 定义需要排除的请求u ...

  7. POJ 1986 裸的LCA

    思路:搞了一发链剖 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...

  8. 洛谷P2598 [ZJOI2009]狼和羊的故事

    题目描述 “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想:狼和羊如此和谐,为什么不尝试羊狼合养呢?说干就干! Orez的羊狼圈 ...

  9. 批处理实现添加java环境变量

    作者:朱金灿 来源:http://blog.csdn.net/clever101 从网上搜了一些资料,再修改测试,终于通过了win7系统的测试.代码如下: @echo off rem 本批处理文件目的 ...

  10. mysql-5.6.15 开启二进制文件

    windows下 mysql 开启二进制文件 在mysql5.6.15下存在  my-default.ini配置文件  复制新建重命名my.ini  在其下加入 一定要在 [mysqld] 下面添加, ...