CF1844D.Row Major

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The row-major order of an r×cr \times c grid of characters AA is the string obtained by concatenating all the rows, i.e. $$ A_{11}A_{12} \dots A_{1c}A_{21}A_{22} \dots A_{2c} \dots A_{r1}A_{r2} \dots A_{rc}. $$

A grid of characters AA is bad if there are some two adjacent cells (cells sharing an edge) with the same character.

You are given a positive integer nn. Consider all strings ss consisting of only lowercase Latin letters such that they are not the row-major order of any bad grid. Find any string with the minimum number of distinct characters among all such strings of length nn.

It can be proven that at least one such string exists under the constraints of the problem.

一个 r×cr \times c 字符网格 AA 的行优先顺序(row-major order)是指将所有行依次连接所得到的字符串,即

A11A12…A1cA21A22…A2c…Ar1Ar2…Arc.A_{11}A_{12} \dots A_{1c}A_{21}A_{22} \dots A_{2c} \dots A_{r1}A_{r2} \dots A_{rc}.

若字符网格 AA 中存在两个相邻单元格(即共享一条边的单元格)具有相同的字符,则称该网格 AA 是坏的(bad)。

给定一个正整数 nn。考虑所有仅由小写拉丁字母组成的字符串 ss,且 ss 不是任何坏网格的行优先顺序。在所有长度为 nn 的此类字符串中,找出一个所含不同字符种类数最少的字符串。

可以证明:在本题约束条件下,至少存在一个满足要求的字符串。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The only line of each test case contains a single integer nn (1≤n≤1061 \le n \le 10^6).

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例仅一行,包含一个整数 nn(1≤n≤1061 \le n \le 10^6)。

保证所有测试用例的 nn 值之和不超过 10610^6。

输出格式

For each test case, output a string with the minimum number of distinct characters among all suitable strings of length nn.

If there are multiple solutions, print any of them.

对于每个测试用例,输出一个字符串,该字符串是所有长度为 nn 的合适字符串中不同字符数量最少的一个。

如果存在多个解,输出其中任意一个即可。

输入输出样例

  • 输入#1

    4
    4
    2
    1
    6

    输出#1

    that
    is
    a
    tomato

说明/提示

In the first test case, there are 33 ways ss can be the row-major order of a grid, and they are all not bad:

t

t

h

t

h

a

t

h

a

t

a

t

It can be proven that 33 distinct characters is the minimum possible.

In the second test case, there are 22 ways ss can be the row-major order of a grid, and they are both not bad:

i

i

s

s

It can be proven that 22 distinct characters is the minimum possible.

In the third test case, there is only 11 way ss can be the row-major order of a grid, and it is not bad.

In the fourth test case, there are 44 ways ss can be the row-major order of a grid, and they are all not bad:

t

t

o

t

o

m

t

o

m

a

t

o

o

m

a

a

t

o

m

t

o

a

t

o

It can be proven that 44 distinct characters is the minimum possible. Note that, for example, the string "orange" is not an acceptable output because it has 6>46 \gt 4 distinct characters, and the string "banana" is not an acceptable output because it is the row-major order of the following bad grid:

b

a

n

a

n

a

在第一个测试用例中,字符串 ss 作为某个网格的行优先顺序(row-major order)共有 33 种可能的方式,且它们全都不构成“坏网格”:

t

t

h

t

h

a

t

h

a

t

a

t

可以证明,33 个互不相同的字符是所能达到的最小值。

在第二个测试用例中,字符串 ss 作为某个网格的行优先顺序共有 22 种可能的方式,且它们全都不构成“坏网格”:

i

i

s

s

可以证明,22 个互不相同的字符是所能达到的最小值。

在第三个测试用例中,字符串 ss 作为某个网格的行优先顺序仅有 11 种可能的方式,且该方式不构成“坏网格”。

在第四个测试用例中,字符串 ss 作为某个网格的行优先顺序共有 44 种可能的方式,且它们全都不构成“坏网格”:

t

t

o

t

o

m

t

o

m

a

t

o

o

m

a

a

t

o

m

t

o

a

t

o

可以证明,44 个互不相同的字符是所能达到的最小值。注意,例如字符串 "orange" 不是可接受的输出,因为它含有 6>46 > 4 个互不相同的字符;而字符串 "banana" 也不是可接受的输出,因为它是如下“坏网格”的行优先顺序:

b

a

n

a

n

a

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

首页