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. 【Git 一】Linux安装Git

    一.Git 的优势 #简单说一下 Git 的优势. 1.版本库本地化,支持离线提交,相对独立不影响协同开发. 2.支持快速切换分支方便合并,比较合并性能好. 3.分布式管理,适应不同的业务场景. 4. ...

  2. [Bug]Python3.x SyntaxError: 'ascii' codec can't decode byte 0xe4 in position

    安装arch后就没再用python了 昨天管服务器的大佬在跑贝叶斯分类器的时候发现正确率有问题 我赶紧去做优化,然后就有这样的报错 Python 3.6.4 (default, Jan 5 2018, ...

  3. 钩子(hooks)—webhook-使用钩子自动触发部署

    钩子(hooks)-webhook http://fighter.blog.51cto.com/1318618/1670667 https://www.lovelucy.info/auto-deplo ...

  4. Mysql 锁表 for update (引擎/事务)

    因为之前用过oracle,知道利用select * for update 可以锁表.所以很自然就想到在mysql中能不能适应for update来锁表呢. 学习参考如下 由于InnoDB预设是Row- ...

  5. POJ——T 1470 Closest Common Ancestors

    http://poj.org/problem?id=1470 Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 20830   ...

  6. 为什么用卷积滤波,而不是非常easy的在频率领域内进行数据的频率处理

    卷积.为了更好的"动态"滤波. 问题来了.为什么用卷积滤波.而不是非常easy的在频率领域内进行数据的频率处理? 为了强调我觉得的答案,已经用blog标题给出了.卷积.为了更好的& ...

  7. BZOJ1045: [HAOI2008]糖果传递&BZOJ1465: 糖果传递&BZOJ3293: [Cqoi2011]分金币

    [传送门:BZOJ1045&BZOJ1465&BZOJ3293] 简要题意: 给出n个数,每个数每次可以-1使得左边或者右边的数+1,代价为1,求出使得这n个数相等的最小代价 题解: ...

  8. Lesson 2 Building your first web page: Part 2

    Tag Diagram You may have noticed that HTML tags come in pairs; HTML has both an opening tag (<tag ...

  9. java.util.logging.FileHandler

    java.util.logging.FileHandler java自带的日志功能,FileHandler可以写日志到文件系统,并且自己维护日志的增删,比c++不知道强多少 FileHandler(f ...

  10. Vue总结(一)

    vue总结 构建用户界面的渐进式框架 渐进式:用到什么功能即可使用转么的框架子模块. 两个核心点 向应的数据绑定 当时图发生改变->自动跟新视图,利用Object.defindProperty中 ...