F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Cyclic antimonotonic permutations

Time Limit: 20000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 318    Accepted Submission(s): 11


Problem Description
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 pi-1, pi, pi+1 (1 < i < n), pi 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 pi as a pointer from i to pi, it should be possible to start at position 1 and follow the pointers and reach all n positions before returning to position 1.
 

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

 

Output
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
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 11:14:48, Gzip enabled