P22414 [CodeChef] DIFFMED
普及
题目描述

Chef is given an integer N. Chef wants to construct $a [permutation] A = [A_{1}, A_{2}, \ldots, A_{N}]$ of ${1, 2, 3, \ldots, N$ } that satisfies the following condition:

Let P_{i} denote the prefix of A of length $i, i.e, P_{i} = [A_{1}, A_{2}, \ldots, A_{i}].$ Then, for every 1 ≤ i < N, it must hold that $\text{median}(P_{i}) \neq \text{median}(P_{i+1})$

Help Chef find such a permutation A. If multiple answers exist, you may print any of them.

Note: The median of an array is defined as follows:
Let A be an (1-indexed) array of length N. Let B be the array obtained by sorting $A. Then \text{median}(A)$ is defined to be $B_{\lceil \frac{N}{2}\right\rceil}$. For example$, \text{median}(${3, 1, 2}) = 2, and $\text{median}(${3, 4, 1, 2}) = 2

------ Input Format ------

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • The first and only line of each test case contains a single integer N.

------ Output Format ------

For each test case, output the required permutation. If multiple answers are possible, you may print any of them.

------ Constraints ------

$1 ≤ T ≤ 30$
$2 ≤ N ≤ 1000$
- The sum of $N$ over all test cases won't exceed $1000$.

----- Sample Input 1 ------
2
2
3

----- Sample Output 1 ------
2 1
2 1 3

----- explanation 1 ------
Test case $1$: The prefixes of the given permutation are $[2]$ and $[2, 1]$, with medians $2$ and $1$ respectively.

Test case $2$: The prefixes of the given permutation are $[2]$ (with median $2$), $[2, 1]$ (with median $1$), and $[2, 1, 3]$ (with median $2$). No two adjacent medians are equal.

输入格式

见题面

输出格式

见题面

样例输入
2 2 3
样例输出
2 1 2 1 3