CF1743B.Permutation Value

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given an integer nn. You have to construct a permutation of size nn.

A permutation is an array where each integer from 11 to ss (where ss is the size of permutation) occurs exactly once. For example, [2,1,4,3][2, 1, 4, 3] is a permutation of size 44; [1,2,4,5,3][1, 2, 4, 5, 3] is a permutation of size 55; [1,4,3][1, 4, 3] is not a permutation (the integer 22 is absent), [2,1,3,1][2, 1, 3, 1] is not a permutation (the integer 11 appears twice).

A subsegment of a permutation is a contiguous subsequence of that permutation. For example, the permutation [2,1,4,3][2, 1, 4, 3] has 1010 subsegments: [2][2], [2,1][2, 1], [2,1,4][2, 1, 4], [2,1,4,3][2, 1, 4, 3], [1][1], [1,4][1, 4], [1,4,3][1, 4, 3], [4][4], [4,3][4, 3] and [3][3].

The value of the permutation is the number of its subsegments which are also permutations. For example, the value of [2,1,4,3][2, 1, 4, 3] is 33 since the subsegments [2,1][2, 1], [1][1] and [2,1,4,3][2, 1, 4, 3] are permutations.

You have to construct a permutation of size nn with minimum possible value among all permutations of size nn.

给你一个整数 nn。你需要构造一个长度为 nn 的排列。

排列是指一个数组,其中从 11 到 ss(ss 为该排列的长度)的每个整数恰好出现一次。例如,[2,1,4,3][2, 1, 4, 3] 是一个长度为 44 的排列;[1,2,4,5,3][1, 2, 4, 5, 3] 是一个长度为 55 的排列;[1,4,3][1, 4, 3] 不是排列(缺少整数 22);[2,1,3,1][2, 1, 3, 1] 不是排列(整数 11 出现了两次)。

排列的一个子段是指该排列的一个连续子序列。例如,排列 [2,1,4,3][2, 1, 4, 3] 共有 1010 个子段:[2][2]、[2,1][2, 1]、[2,1,4][2, 1, 4]、[2,1,4,3][2, 1, 4, 3]、[1][1]、[1,4][1, 4]、[1,4,3][1, 4, 3]、[4][4]、[4,3][4, 3] 和 [3][3]。

一个排列的值定义为:其所有子段中,本身也是排列的子段的个数。例如,[2,1,4,3][2, 1, 4, 3] 的值为 33,因为子段 [2,1][2, 1]、[1][1] 和 [2,1,4,3][2, 1, 4, 3] 都是排列。

你需要构造一个长度为 nn 的排列,使其值在所有长度为 nn 的排列中尽可能小。

输入格式

The first line contains one integer tt (1≤t≤481 \le t \le 48) — the number of test cases.

Then, tt lines follow. The ii-th of them contains one integer nn (3≤n≤503 \le n \le 50) representing the ii-th test case.

第一行包含一个整数 tt(1≤t≤481 \le t \le 48)—— 测试用例的数量。

接下来有 tt 行。其中第 ii 行包含一个整数 nn(3≤n≤503 \le n \le 50),表示第 ii 个测试用例。

输出格式

For each test case, print nn integers — the permutation of size nn with minimum possible value. If there are multiple such permutations, print any of them.

对于每个测试用例,输出 nn 个整数——即一个大小为 nn 的排列,其对应值尽可能小。如果存在多个满足条件的排列,输出其中任意一个即可。

输入输出样例

  • 输入#1

    2
    5
    6

    输出#1

    1 4 3 5 2
    4 1 6 2 5 3

说明/提示

In the first example, the permutation [1,4,3,5,2][1, 4, 3, 5, 2] is one of the possible answers; its value is 22.

In the second example, the permutation [4,1,6,2,5,3][4, 1, 6, 2, 5, 3] is one of the possible answers; its value is 22.

在第一个例子中,排列 [1,4,3,5,2][1, 4, 3, 5, 2] 是一个可能的答案;其值为 22。

在第二个例子中,排列 [4,1,6,2,5,3][4, 1, 6, 2, 5, 3] 是一个可能的答案;其值为 22。

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

首页