Codeforces Round 829 (Div. 2)
B
Kevin and Permutation
Codeforces
800
原题
← AC1 →
翻译中…

For his birthday, Kevin received the set of pairwise distinct numbers $1, 2, 3, \ldots, n$ as a gift.

翻译中…

He is going to arrange these numbers in a way such that the minimum absolute difference between two consecutive numbers be maximum possible. More formally, if he arranges numbers in order $p_1, p_2, \ldots, p_n$, he wants to maximize the value $$\min \limits_{i=1}^{n - 1} \lvert p_{i + 1} - p_i \rvert,$$ where $|x|$ denotes the absolute value of $x$.

翻译中…

Help Kevin to do that.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. Description of the test cases follows.

翻译中…

The only line of each test case contains an integer $n$ ($2 \le n \leq 1\,000$) — the size of the set.

翻译中…

Output

翻译中…

For each test case print a single line containing $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \le p_i \le n$) describing the arrangement that maximizes the minimum absolute difference of consecutive elements.

翻译中…

Formally, you have to print a permutation $p$ which maximizes the value $\min \limits_{i=1}^{n - 1} \lvert p_{i + 1} - p_i \rvert$.

翻译中…

If there are multiple optimal solutions, print any of them.

翻译中…

Note

翻译中…

In the first test case the minimum absolute difference of consecutive elements equals $\min \{\lvert 4 - 2 \rvert, \lvert 1 - 4 \rvert, \lvert 3 - 1 \rvert \} = \min \{2, 3, 2\} = 2$. It's easy to prove that this answer is optimal.

翻译中…

In the second test case each permutation of numbers $1, 2, 3$ is an optimal answer. The minimum absolute difference of consecutive elements equals to $1$.

翻译中…

样例

Input #1
2
4
3
Output #1
2 4 1 3
1 2 3
InputCopy OutputCopy
题目信息
题号
1754B
时间限制
1 s
内存限制
256 MB
标签
构造
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。