雅礼集训D4T2 gre

很毒瘤。

考虑递归构造。

首先k=1的时候,答案为a。

增加k时,将现有字符串中的字符全部顺移一位(aabaa变成bbcbb)

然后新字符串先放两个a,然后遍历旧字符串,每次遇到一个b就放ba,直到放完,然后再放一个a。

最后把不到n的部分拿a补上。

#include <assert.h>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
using int_t = long long int;
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

const int_t LARGE = 1e5;

void process() {
    int_t n, k;
    cin >> n >> k;
    std::vector<char> buf;
    buf.push_back('a');
    for (int_t i = 1; i <= k - 1; i++) {
        std::vector<char> next{'a', 'a'};
        for (char chr : buf) {
            next.push_back(chr + 1);
            if (chr == 'a') {
                next.push_back('a');
            }
        }
        next.push_back('a');
        buf = next;
    }
#ifdef DEBUG
    for (char chr : buf) cout << chr << " ";
    cout << endl;
#endif
    if (n < buf.size()) {
        printf("CiYe\n");
        return;
    }
    for (int_t i = 1; i <= n - buf.size(); i++) {
        printf("a");
    }
    for (char chr : buf) printf("%c", chr);
    cout << endl;
}

int main() {
    int_t T;
    cin >> T;
    while (T--) {
        process();
    }

    return 0;
}

 

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理