QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#3117. Cyclic antimonotonic permutations

الإحصائيات

A permutation is a sequence of integers which contains each integer from $1$ to $n$ exactly once. In this problem we are looking for permutations with special properties:

  1. Antimonotonic: for each consecutive $3$ values $p_{i-1}, p_i, p_{i+1}$ ($1 < i < n$), $p_i$ should either be the smallest or the biggest of the three values.
  2. Cyclic: The permutation should consist of only one cycle, that is, when we use $p_i$ as a pointer from $i$ to $p_i$, it should be possible to start at position $1$ and follow the pointers and reach all $n$ positions before returning to position $1$.

Input Specification

The input file contains several test cases. Each test case consists of a line containing an integer $n$, ($3 ≤ n ≤ 10^6$), the number of integers in the permutation. Input is terminated by $n=0$.

Output Specification

For each test case print a permutation of the integers $1$ to $n$ which is both antimonotonic and cyclic. In case there are multiple solutions, you may print any one. Separate all integers by whitespace characters.

Sample Input

3
5
10
0

Sample Output

3 1 2
4 5 2 3 1
6 10 2 9 3 5 4 7 1 8
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.