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

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

分析:打表发现abaa可以很好的截断回文串,然后分类讨论构造答案。


#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#define INF 0x3f3f3f3f
#define eps 1e-9
#define MAXN 10005
using namespace std;
int n;
char s[MAXN],p[MAXN];
int main()
{scanf("%d",&n);if(n <= 7){for(int i = 1;i < n;i++) cout<<i<<" : NO"<<endl;for(int i = 0;i < n;i++) s[i] = 'a';s[n] = '\0';cout<<n<<" : "<<s<<endl;return 0;}if(n == 8){for(int i = 1;i < 7;i++) cout<<i<<" : NO"<<endl;cout<<7<<" : bbabaabb"<<endl;cout<<8<<" : "<<"aaaaaaaa"<<endl;return 0;}for(int i = 1;i < 8;i++) cout<<i<<" : NO"<<endl;p[0] = 'b',p[1] = 'b',p[2] = 'a',p[3] = 'b',p[4] = 'a',p[5] = '\0';for(int i = 8;i < n;i++){int leng = strlen(p);p[leng] = 'a';p[++leng] = '\0';for(int j = 0;j < n;j++) s[j] = p[j % leng];s[n] = '\0';cout<<i<<" : "<<s<<endl;}for(int i = 0;i < n;i++) s[i] = 'a';s[n] = '\0';cout<<n<<" : "<<s<<endl;
}

Ural 2037. Richness of binary words (打表+构造)相关推荐

  1. Ural 2037. Richness of binary words 打表找规律 构造

    2037. Richness of binary words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2037 Descripti ...

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

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

  3. 哈希表构造与处理冲突方法

    我们知道:哈希表是一个固定大小的数组,数组的每个元素是一个链表(单向或双向)的头指针.如果Key一样,则在一起,如果Key不一样,则不在一起.哈希表的查询是飞快的.因为它不需要从头搜索,它利用Key的 ...

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

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

  5. URAL 2045 Richness of words (回文子串,贪心)

    Richness of words 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/J Description For each ...

  6. Ural 2045 Richness of words

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2045 题意:给一个数n,对于每一个i∈[1,n],输出一个长度为n的字符串si,且si里 ...

  7. 02-NLP-04基于统计的翻译系统-03-短语翻译表构造——短语抽取

    统计翻译模型核心就是基于短语的翻译(短语与短语的对应). 上一讲中词到词的对应就是为了短语对应做铺垫. 一致性短语需要满足三个条件: 条件1:如果"北京 房价"对应的英文短语中包含 ...

  8. 【CF1311E】Construct the Binary Tree【增量构造】【复杂度证明】

    题意:给定nnn和ddd,构造或判断无法构造一棵二叉树使得所有点的深度(定义为到根距离)之和为ddd. n,d≤5000n,d\leq 5000n,d≤5000 显然可以算出有解的ddd的下界和上界, ...

  9. MYSQL的binary解决mysql数据大小写敏感问题

    [本文为转载]http://www.jb51.net/article/41546.htm BINARY不是函数,是类型转换运算符,它用来强制它后面的字符串为一个二进制字符串,可以理解为在字符串比较的时 ...

最新文章

  1. 和12岁小同志搞创客开发:手撕代码,做一款火焰报警器
  2. java restful netty_Java RESTful 框架的性能比较
  3. 用编码实现gridview的创建!(一)(转www.asp.net)
  4. Android 打开另一个APP,并传参
  5. bzoj4950(二分图最大匹配)
  6. flash遨游缓存问题
  7. python计算器程序代码_7_python之路之python计算器
  8. 性能监控工具——Cacti安装文档
  9. 错误解决办法:_ZNSaIcED1Ev@@GLIBCXX_3.4
  10. 必看干货!五个步骤帮您成功实施IT SLA
  11. 英特尔第十代处理器为什么不支持win7_为什么7代CPU不支持WIN7操作系统?
  12. gis核密度分析工具_核密度分析工具的初探(Kernel Density)
  13. 钉钉审批流API接口
  14. 电子爱好者都应该至少有一台示波器
  15. 配置mpls vpn基本组网-intranet
  16. glog安装配置及使用
  17. pyramid框架_Python Pyramid Web框架简介
  18. Ubuntu 配置电驴
  19. Python分析微信好友性别比例
  20. Unity3D-Baked Lightmapping 示例学习

热门文章

  1. EasyGBS主子码流都为H.265时,切换出现花屏如何解决?
  2. 给我写信 wyz831201王玉镇
  3. LOL服务器人数最新,英雄联盟大区人数排名
  4. 算法概念:大O表示法/小o表示法/Ω/Θ
  5. Vocabulary and Phrase in Paper of Computer Vision (Updating)
  6. 区块链知识点杂记(并不全面)
  7. 局域网唤醒 外网无法唤醒_为您的网络设置局域网唤醒控制面板
  8. 互金协会:各相关机构即日起就高息现金贷等违规业务开展自查
  9. BT级别的IC项目验证基本流程
  10. 微信用计算机,技巧:计算机可以使用微信吗?