A. Smallest Permutation
Time Limit: 0.5 s
Memory Limit: 256.0 MB
Description
You are given a positive integer \(N\) which is greater than 1.
Your task is to construct the lexicographically smallest permutation \(P\) of integers from \(1\) to \(N\) such that:
A permutation \(A\) is lexicographically smaller than a permutation \(B\) if at the first position where they differ, the element in \(A\) is smaller than in \(B\).
For example:
1 3 2
is lexicographically smaller than2 1 3
because1 < 2
.
Among all valid permutations where \(P_i \ne i\), you must choose the lexicographically smallest one.
Input
The first line contains an integer \(T\) \((1 \le T \le 99)\) — the number of test cases.
Each of the next \(T\) lines contains a single integer \(N\) \((2 \le N \le 100)\).
Output
For each test case, print:
- A line containing \(N\) space-separated integers — the required permutation
Sample
Input | Output |
---|---|
|
|
Third test case
:
The resulting permutation is:
2 1 4 3
This satisfies:
\(P_1 = 2 ≠ 1\)
\(P_2 = 1 ≠ 2\)
\(P_3 = 4 ≠ 3\)
\(P_4 = 3 ≠ 4\)
Among all valid permutations, this is the lexicographically smallest one.
So, the output is:
2 1 4 3
Information
- ID
- 1210
- Difficulty
- 1
- Category
- Implementation Click to Show
- Tags
- # Submissions
- 148
- Accepted
- 88
- Accepted Ratio
- 59%
- Uploaded By
Related
In following contests: