CF1461A.String Generation

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

One fall day Joe got bored because he couldn't find himself something interesting to do. Marty suggested Joe to generate a string of length nn to entertain him somehow. It didn't seem particularly difficult, but Joe's generated string had to follow these rules:

  • the string may only contain characters 'a', 'b', or 'c';
  • the maximum length of a substring of this string that is a palindrome does not exceed kk.

A string aa is a substring of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end. For example, strings "a", "bc", "abc" are substrings of a string "abc", while strings "ac", "ba", "cba" are not.

A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, strings "abccba", "abbba", "aba", "abacaba", "a", and "bacab" are palindromes, while strings "abcbba", "abb", and "ab" are not.

Now Joe wants to find any correct string. Help him! It can be proven that the answer always exists under the given constraints.

一个秋日,Joe 因找不到有趣的事情做而感到无聊。Marty 建议 Joe 生成一个长度为 nn 的字符串来娱乐自己。这看起来并不特别困难,但 Joe 生成的字符串必须满足以下规则:

  • 字符串只能包含字符 'a'、'b' 或 'c';
  • 该字符串中任意回文子串的最大长度不超过 kk。

若字符串 aa 可通过从字符串 bb 的开头删除若干(可能为零个或全部)字符,并从结尾删除若干(可能为零个或全部)字符而得到,则称 aa 是 bb 的一个子串。例如,字符串 "a"、"bc"、"abc" 都是 "abc" 的子串,而 "ac"、"ba"、"cba" 则不是。

若一个字符串从左到右读与从右到左读完全相同,则称其为回文串。例如,字符串 "abccba"、"abbba"、"aba"、"abacaba"、"a" 和 "bacab" 都是回文串,而 "abcbba"、"abb" 和 "ab" 则不是。

现在 Joe 想要找出任意一个满足条件的字符串。请帮助他!在给定约束下,可以证明答案一定存在。

输入格式

Each test contains one or more test cases. The first line contains the number of test cases tt (1≤t≤101 \le t \le 10).

The only line of each test case contains two integers nn and kk (1≤k≤n≤1 0001 \le k \le n \le 1\,000) — the required string length and the maximum length of a palindrome substring, respectively.

每个测试包含一个或多个测试用例。第一行包含测试用例的数量 tt(1≤t≤101 \le t \le 10)。

每个测试用例仅有一行,包含两个整数 nn 和 kk(1≤k≤n≤1 0001 \le k \le n \le 1\,000),分别表示所要求的字符串长度和回文子串的最大长度。

输出格式

For each test case, print any string that satisfies the conditions from the problem statement. If there are multiple correct answers, you can print any one of them. It can be proven that the answer always exists under the given constraints.

对于每个测试用例,输出任意一个满足题目条件的字符串。如果存在多个正确答案,你可以输出其中任意一个。在给定约束条件下,可以证明答案一定存在。

输入输出样例

  • 输入#1

    2
    3 2
    4 1

    输出#1

    aab
    acba

说明/提示

In the first test case of the example, the palindrome substring with the maximum length is "aa". Its length does not exceed 22, so it fits.

In the second test case all palindrome substrings have the length one.

在示例的第一个测试用例中,最长的回文子串是 "aa"。其长度不超过 22,因此满足条件。

在第二个测试用例中,所有回文子串的长度均为 11。

输入解题思路,AI测评打分。不知道怎么写?

首页