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. AIX 6.1 Oracle 10G 数据库GoldenGate实施

    安装环境说明: 源端:AIX 6.1 10.190.1.215 目标端:Linux 10.191.1.10 1:源端创建goldengate 表空间. 表空间的要求:最小500m,大点3-5G,设置自 ...

  2. Mac上vmware虚拟机Windows10安装JDK8及配置环境

    1.jdk8下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.双击下载的jdk进行安装 3.安装成功之 ...

  3. package.json 中 scripts

    "name": "webpack-study1", "version": "1.0.0", "main&quo ...

  4. TCP的连接管理

    创建连接:(三次握手) 第一步: 客户端向服务器发送一个报文,该报文不含有数据段,SYN=1,随机产生sequence number(随机产生可用于避免某些安全性攻击) 第二步: 服务器收到报文,为这 ...

  5. HDU 2253 Longest Common Subsequence Again

    其实这个题我还不会,学长给了一个代码交上去过了,据说用到了一种叫做位压缩的技术,先贴代码吧,以后看懂了再来写 #include <stdio.h> #include <string. ...

  6. HDFS 文件系统流程图。PB级文件存储时序图。

    大小文件通吃, 热点hash功能. 全局唯一KV索引. 百度网盘模式.断点续传功能.MR分析功能. 来自为知笔记(Wiz)

  7. ZooKeeper 特性

    ZooKeeper 拥有一个层次的命名空间.(like distributed)       注意:ZooKeeper 中不许使用相对路径.   一    ZooKeeper 数据模型         ...

  8. hbase启动报错

    前一段时间vmware上的ubuntu的hbase用不了了,而hadoop能正常的操作,非常的奇怪. 错误信息好像是connect fail, RPC什么的,看来跟网路有关. 想起以前曾经解决过hba ...

  9. Java Web乱码分析及解决方式(二)——POST请求乱码

    引言 GET请求的本质表现是将请求參数放在URL地址栏中.form表单的Method为GET的情况.參数会被浏览器默认编码,所以乱码处理方案是一样的. 对于POST请求乱码.解决起来要比GET简单.我 ...

  10. Simditor用法

    一不小心接触到Simditor,瞬间被它优美极简的界面所吸引.Simditor是Tower开源的所见即所得的在线富文本编辑器. Simditor的理念是保持简单,避免过度的功能,每个特性都追求极致的用 ...