CF2231A.Construct an Array

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an integer nn. You need to construct an array of integers a1,a2,…,ana_1, a_2, \ldots, a_n such that the following conditions are satisfied:

  • 1≤ai≤2⋅n1 \leq a_i \leq 2 \cdot n for all ii from 11 to nn.
  • All elements of the array and the sums of adjacent elements are pairwise distinct. In other words, among the numbers a1,a2,…,an,a1+a2,a2+a3,…,an−1+an{a_1, a_2, \ldots, a_n, a_1 + a_2, a_2 + a_3, \ldots, a_{n - 1} + a_n}, there should not be two equal numbers.

给你一个整数 nn。你需要构造一个整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n,使得以下条件均满足:

  • 对所有 ii(从 11 到 nn),均有 1≤ai≤2⋅n1 \leq a_i \leq 2 \cdot n。
  • 数组中所有元素以及所有相邻元素之和两两互不相同。换言之,在集合 {a1,a2,…,an,a1+a2,a2+a3,…,an−1+an}\{a_1, a_2, \ldots, a_n, a_1 + a_2, a_2 + a_3, \ldots, a_{n - 1} + a_n\} 中,不应存在两个相等的数。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). The description of the test cases follows.

The only line of each test case contains one integer nn (1≤n≤5001 \le n \le 500).

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

每个测试用例仅有一行,包含一个整数 nn(1≤n≤5001 \le n \le 500)。

输出格式

For each test case, output an array of length nn that satisfies the condition of the problem. It can be shown that such an array always exists under the given constraints.

对于每个测试用例,输出一个长度为 nn 的数组,使其满足题目的条件。在给定约束下,可以证明这样的数组总是存在的。

输入输出样例

  • 输入#1

    3
    1
    3
    6

    输出#1

    1 
    6 2 3
    8 1 11 2 3 4

说明/提示

In the second example, all elements and adjacent sums form the set 6,2,3,8,5\textbf{6}, \textbf{2}, \textbf{3}, 8, 5, all of whose elements are distinct.

In the third example, all elements and adjacent sums form the set 8,1,11,2,3,4,9,12,13,5,7\textbf{8}, \textbf{1}, \textbf{11}, \textbf{2}, \textbf{3}, \textbf{4}, 9, 12, 13, 5, 7, whose elements are also distinct.

在第二个例子中,所有元素及相邻元素之和构成集合 6,2,3,8,5\textbf{6}, \textbf{2}, \textbf{3}, 8, 5,其中所有元素互不相同。

在第三个例子中,所有元素及相邻元素之和构成集合 8,1,11,2,3,4,9,12,13,5,7\textbf{8}, \textbf{1}, \textbf{11}, \textbf{2}, \textbf{3}, \textbf{4}, 9, 12, 13, 5, 7,其中所有元素也互不相同。

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

首页