2037. Richness of binary words

题目连接:

http://acm.timus.ru/problem.aspx?space=1&num=2037

Description

For each integer i from 1 to n, you must print a string si of length n consisting of letters ‘a’ and ‘b’ only. The string si must contain exactly i distinct palindrome substrings. Two substrings are considered distinct if they are different as strings.

Input

The input contains one integer n (1 ≤ n ≤ 2000).

Output

You must print n lines. If for some i, the answer exists, print it in the form “i : si” where si is one of possible strings. Otherwise, print “i : NO”.

Sample Input

4

Sample Output

1 : NO

2 : NO

3 : NO

4 : aaaa

Hint

题意

让你构造长度为n,字符集为2,且本质不同的回文串恰好i个的字符

无解输出no

题解:

打表找规律,比较容易发现答案其实就是aababb->aaababb->aaaababb的循环,这样的。

然后输出就好了。

代码

#include <bits/stdc++.h>

using namespace std;
int N; void solve_special(){
if( N <= 7 ){
for(int i = 1 ; i < N ; ++ i) printf("%d : NO\n" , i);
printf("%d : ",N);
for(int j = 1 ; j <= N ; ++ j) putchar('a');
puts("");
}else if( N == 8 ){
cout << "1 : NO" << endl;
cout << "2 : NO" << endl;
cout << "3 : NO" << endl;
cout << "4 : NO" << endl;
cout << "5 : NO" << endl;
cout << "6 : NO" << endl;
cout << "7 : aababbaa" << endl;
cout << "8 : aaaaaaaa" << endl;
}else if( N == 9 ){
cout << "1 : NO" << endl;
cout << "2 : NO" << endl;
cout << "3 : NO" << endl;
cout << "4 : NO" << endl;
cout << "5 : NO" << endl;
cout << "6 : NO" << endl;
cout << "7 : NO" << endl;
cout << "8 : aaababbaa" << endl;
cout << "9 : aaaaaaaaa" << endl;
}else if( N == 10 ){
cout << "1 : NO" << endl;
cout << "2 : NO" << endl;
cout << "3 : NO" << endl;
cout << "4 : NO" << endl;
cout << "5 : NO" << endl;
cout << "6 : NO" << endl;
cout << "7 : NO" << endl;
cout << "8 : aaababbaaa" << endl;
cout << "9 : aaaababbaa" << endl;
cout << "10 : aaaaaaaaaa" << endl;
}
} void solve(){
int target = (N-11)/2 + 2 ;
for(int i = 1 ; i < 8 ; ++ i){
printf("%d : NO\n" , i);
}
int cur = 2;
for(int i = 8 ; i < N ; ++ i){
int len = 0 , flag = 0 , rs = cur;
printf("%d : " , i);
while( len < N ){
if( flag == 0 ){
putchar('a');
-- rs;
}else if( flag == 1 ){
if( rs == 3 ) putchar('a');
else putchar('b');
-- rs;
}
if( rs == 0 ){
flag ^= 1;
if( flag == 0 ) rs = cur;
else rs = 4;
}
++ len;
}
if( cur == target ) cur += 2;
else ++ cur;
puts("");
}
printf("%d : ",N);
for(int i = 1 ; i <= N ; ++ i) putchar('a');
puts("");
} int main(int argc,char *argv[]){
//freopen("KO.txt","w",stdout);
scanf("%d",&N);
if( N < 10 ) solve_special();
else if( N == 10 ){
cout << "1 : NO" << endl;
cout << "2 : NO" << endl;
cout << "3 : NO" << endl;
cout << "4 : NO" << endl;
cout << "5 : NO" << endl;
cout << "6 : NO" << endl;
cout << "7 : NO" << endl;
cout << "8 : aaababbaaa" << endl;
cout << "9 : aaaababbaa" << endl;
cout << "10 : aaaaaaaaaa" << endl;
}else solve();
return 0;
}

Ural 2037. Richness of binary words 打表找规律 构造的更多相关文章

  1. URAL 2037 Richness of binary words (回文子串,找规律)

    Richness of binary words 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/B Description Fo ...

  2. codeforces#1159D. The minimal unique substring(打表找规律+构造)

    题目链接: https://codeforces.com/contest/1159/problem/D 题意: 构造一个长度为$n$的$01$串,最小特殊连续字串的长度为$k$ 也就是,存在最小的$k ...

  3. Ural 2045. Richness of words 打表找规律

    2045. Richness of words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2045 Description For ...

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

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

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

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

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

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

  7. HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)

    Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  8. 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用

    转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html    ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...

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

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

随机推荐

  1. postman提取接口的返回值及动态设置变量(一)

    一.提取接口返回值   1.当返回值是返回JSON时 let json = JSON.parse(responseBody); // responseBody是包含整个返回内容的字符串 let foo ...

  2. 使用mybatisgenerator 辅助工具逆向工程

    使用mybatisgenerator 辅助工具生成单表的dao层接口,mapper xml 文件以及实体类,复杂的还得人手动去编写哈...所以我也不觉得这玩意儿在项目简单情况下有什么鸟用... wha ...

  3. [整理]Visual Studio 的Application Insights

    简单介绍 Application Insights(预览版) Visual Studio 的Application Insights插件简介 Application Insights for Visu ...

  4. codeforces 235 div2 B. Sereja and Contests

    Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good ...

  5. ZYNQ. DMA基本用法

    DMA环路测试 vivadoblock zynq7 + dma +fifo sdk 中可以导入 demo demo 中 默认都是 一个字节8bit数据 的测试程序. 如果是其他长度的数据,不仅要修改数 ...

  6. 如何使用gifsicle压缩gif图片

    最近我写了一些关于如何将各种形式的多媒体格式相互转换的文章,特别是GIF动图方面的,比如如何将小视频转换成GIF动图或将GIF动图转换成视频,有很多像ImageMagick,ffmpeg这样的工具帮助 ...

  7. C++笔试易错题集(持续更新)

    1.如下代码输出结果是什么? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> char *myString() {     ...

  8. CodeForces Contest #1114: Round #538 (Div. 2)

    比赛传送门:CF #1114. 比赛记录:点我. 又 FST 了. [A]Got Any Grapes? 题意简述: 有三个人,第一个人需要吃绿色葡萄至少 \(a\) 个,第二个人需要吃绿色和紫色葡萄 ...

  9. 【linux kernel】 中断处理-中断下半部【转】

    转自:http://www.cnblogs.com/embedded-tzp/p/4453987.html 欢迎转载,转载时需保留作者信息,谢谢. 邮箱:tangzhongp@163.com 博客园地 ...

  10. Visual Studio 2013更新内容简介

    前言 VS2013终于发布了,虽然之前自己使用VS2010和VS2012的时间也不长,尤其是VS2012这自己刚刚也没用多久,看到VS2013发布了,自己忍不住也下载了下来,官网肯定可以下载,不过自己 ...