CF2188A.Divisible Permutation

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an integer nn. Construct a permutation∗^{\text{∗}} pp of length nn satisfying the following condition:

  • ∣pi−pi+1∣\lvert p_i - p_{i+1} \rvert is divisible by ii for every 1≤i≤n−11 \le i \le n-1.

It can be proven that such a permutation always exists under the constraints of the problem.

∗^{\text{∗}}A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

给你一个整数 nn。请构造一个长度为 nn 的排列∗^{\text{∗}} pp,使其满足以下条件:

  • 对每个 1≤i≤n−11 \le i \le n-1,∣pi−pi+1∣\lvert p_i - p_{i+1} \rvert 都能被 ii 整除。

可以证明,在本题的约束条件下,这样的排列总是存在的。

∗^{\text{∗}} 长度为 nn 的排列是指由 11 到 nn 中互不相同的 nn 个整数以任意顺序组成的数组。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,但 [1,2,2][1,2,2] 不是排列(数组中 22 出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n=3,但数组中出现了 44)。

输入格式

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 a single integer nn (2≤n≤1002 \le n \le 100) — the length of the permutation pp to be constructed.

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

每个测试用例仅有一行,包含一个整数 nn(2≤n≤1002 \le n \le 100)——即待构造的排列 pp 的长度。

输出格式

For each test case, output nn integers p1,p2,…,pnp_1,p_2,\ldots,p_n (1≤pi≤n1 \le p_i \le n, all pip_i-s are distinct) — the permutation you constructed.

If there are multiple valid permutations, you may output any of them.

对于每个测试用例,输出 nn 个整数 p1,p2,…,pnp_1,p_2,\ldots,p_n(其中 1≤pi≤n1 \le p_i \le n,且所有 pip_i 互不相同)——即你构造出的排列。

若存在多个合法的排列,你可以输出其中任意一个。

输入输出样例

  • 输入#1

    2
    2
    3

    输出#1

    1 2
    2 3 1

说明/提示

In the first test case, p=[1,2]p=[1,2] satisfies the condition because ∣p1−p2∣=∣1−2∣=1\lvert p_1-p_2\rvert=\lvert 1-2\rvert=1, which is divisible by 11.

In the second test case, p=[2,3,1]p=[2,3,1] satisfies the condition because:

  • ∣p1−p2∣=∣2−3∣=1\lvert p_1-p_2\rvert=\lvert 2-3\rvert=1, which is divisible by 11, and
  • ∣p2−p3∣=∣3−1∣=2\lvert p_2-p_3\rvert=\lvert 3-1\rvert=2, which is divisible by 22.

在第一个测试用例中,p=[1,2]p=[1,2] 满足条件,因为 ∣p1−p2∣=∣1−2∣=1\lvert p_1-p_2\rvert=\lvert 1-2\rvert=1,而 11 能被 11 整除。

在第二个测试用例中,p=[2,3,1]p=[2,3,1] 满足条件,因为:

  • ∣p1−p2∣=∣2−3∣=1\lvert p_1-p_2\rvert=\lvert 2-3\rvert=1,而 11 能被 11 整除;
  • ∣p2−p3∣=∣3−1∣=2\lvert p_2-p_3\rvert=\lvert 3-1\rvert=2,而 22 能被 22 整除。

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

首页