URAL 2037 Richness of binary words

B - Richness of binary words
Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

For each integer  i from 1 to  n, you must print a string  s i of length  n consisting of letters ‘a’ and ‘b’ only. The string  s i 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 :   s i” where  s i 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;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值