B - Richness of binary words

Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status Practice URAL 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

input output
4
1 : NO
2 : NO
3 : NO
4 : aaaa

一个字符串只能由字符a b组成 给定一个数字n  问从1~n 能不能有一个字符串 使得这个字符串里面的回文子串的个数有i个 有就输出这个字符串 否则就输出NO

一开始模拟了很多样例。。。对于长度为n的字符串只能找到回文子串个数为n的 所以就猜想除了n 其他都是NO

然后就WA了

后来 暴力了之后发现一个字符串出现的比较频繁 abbaba

后来发现这是一个循环结 整个的字符串的个数是跟这段字符串有关的。。。

我是搬运工

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 10010
#define MAXM 100010
#define INF 99999999
#define ll __int64
#define bug cout<<"here"<<endl
#define fread freopen("ceshi.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)using namespace std;inline int Read()
{char ch;int a = 0;while((ch = getchar()) == ' ' | ch == '\n');a += ch - '0';while((ch = getchar()) != ' ' && ch != '\n'){a *= 10;a += ch - '0';}return a;
}inline void Print(int a)
{if(a>9)Print(a/10);putchar(a%10+'0');
}char ss[] = "abbaba";int main()
{//fread;int n;while(~scanf("%d", &n)){if(n <= 7){for(int i = 1; i < n; i++){Print(i);puts(" : NO");}Print(n);putchar(' '), putchar(':'), putchar(' ');for(int i = 1; i <= n; i++) putchar('a');puts("");}else if(n == 8){for(int i = 1; i < 7; i++){Print(i);puts(" : NO");}puts("7 : aabbabaa");Print(n);putchar(' '), putchar(':'), putchar(' ');for(int i = 1; i <= n; i++) putchar('a');puts("");}else{for(int i = 1; i <= 7; i++){Print(i);puts(" : NO");}for(int i = 8; i < n; i++){Print(i);putchar(' '), putchar(':'), putchar(' ');for(int j = 0; j < i - 8 + 1; j++) putchar('a');int loop = (n - (i - 8 + 1)) / 6, res = (n - (i - 8 + 1)) % 6;while(loop--){
//                    printf("abbaba");putchar('a');putchar('b');putchar('b');putchar('a');putchar('b');putchar('a');}for(int j = 0; j < res; j++) putchar(ss[j]);puts("");}Print(n);putchar(' '), putchar(':'), putchar(' ');
//            printf("%d : ", n);for(int i = 1; i <= n; i++) putchar('a');puts("");}}return 0;
}

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. Ural 2037. Richness of binary words (打表+构造)

    Description For each integer i from 1 to n, you must print a string si of length n consisting of let ...

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

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

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

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

  6. Ural 2045 Richness of words

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

  7. URAL 1081 Binary Lexicographic Sequence

    URAL 1081 思路 状态:dp[i]表示长度为i的方案数 初始状态:dp[0]=1,dp[1]=2 状态转移:dp[i]=dp[i-1]+dp[i-2],在长度为i-1的串的前面加0,在长度为i ...

  8. Ural(Timus) 1081. Binary Lexicographic Sequence

    DP(解码) 题意:给出一个串的长度n,串只有0,1组成,但是不能有两个相邻的1.按字典序给串排列,最先肯定是0000,接着是0001,依此类推.给一个数字m,输出在长度为n的情况下,第m个排列的串是 ...

  9. Binary XML file line : Error inflating class unknown(记录一个很内伤的错误)

    异常信息指出了在51行,我的51行是这个 <ImageView         android:id="@+id/iv_information_commend"       ...

  10. 107. Binary Tree Level Order Traversal II

    题目 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from l ...

最新文章

  1. 硬币(计算n分有几种表示法)
  2. python代码计算图像的分辨率
  3. 横河压力变送器选型_压力变送器的原理和选型技巧
  4. Web服务器安全设置
  5. 远期合约(Forwards/Forward Contract )
  6. Jenkins分层作业和作业状态汇总
  7. 华为留一手鸿蒙,华为“留一手”?华为P40或采用安卓+鸿蒙双系统!
  8. 《学习》13权限管理
  9. 致敬CondConv!Intel提出即插即用的“万金油”动态卷积ODConv
  10. perl判断变量是数值_Perl学习12之defined undef使用
  11. 【知识图谱系列】基于2D卷积的知识图谱嵌入
  12. 适用于ActiveX v18.6 x86的Codejock Xtreme Suite Pro
  13. 计算机一级安装包怎么升级,详细教您win7如何升级为sp1
  14. h5页面 请在微信客户端打开链接_电脑版微信网页授权提示请在微信客户端打开链接?...
  15. Scanf函数,取地址符和字符数组的联系
  16. 静态网页的基本结构及标签
  17. tp810c桥接_TP-Link双无线路由器开启WDS桥接设置步骤
  18. 基于matlab的动态心形图案
  19. 三角形周长最短问题_什么样的三角形周长最短
  20. 毛刺现象 java_硬件毛刺

热门文章

  1. 制作u盘linux课程报告,定制U盘Linux系统总结报告-Linux文档类资源
  2. (转)Windows 批处理(bat)语法大全
  3. 利用HttpClient4,实现get,post 参数,post json,post file
  4. 解读国密非对称加密算法SM2
  5. 简单的木马编写之服务端篇
  6. 人机大战!人工智能轻松打败美国空军
  7. Linux桌面词典 GoldenDict词典
  8. iphone7字体风格怎么改_苹果7怎么更改字体样式 苹果手机换好看的字体
  9. es文件管理复制到fpt服务器,达人教你玩应用:ES文件浏览器之文件互传
  10. 终于找到一个功能全面的番茄钟时间管理工具:myPomodoro for Mac