Little Frog (Codeforces 53C)
Tags: Others, constructive algorithms

Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are n mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him.

Input: The single line contains a number n (1 ≤ n ≤ 104) which is the number of mounds.

Output: Print n integers pi (1 ≤ pi ≤ n) which are the frog's route plan.   All the pi's should be mutually different.  All the |pi–pi + 1|'s should be mutually different (1 ≤ i ≤ n - 1). If there are several solutions, output any.


Sample Inputs:
2

3

Sample Outputs:
1 2

1 3 2

Solution (Python):
import sys

def construct(number_of_mounds):
    start_pos = 1
    end_pos = number_of_mounds
    turn = 0
    while start_pos <= end_pos:
        if not turn % 2:
            print(f'{start_pos}', end=' ')
            start_pos += 1
        else:
            print(f'{end_pos}', end=' ')
            end_pos -= 1
        turn += 1
for line in sys.stdin:
    number = [int(x) for x in line.strip().split()]
construct(number[0])

Solution (Python):
num = input()
num_list = list(range(2, int(num) + 1))
output = '1'
while num_list:
    output += ' ' + str(num_list[-1])
    num_list.pop()
    if not num_list:
        break
    output += ' ' + str(num_list[0])
    num_list.pop(0)
print(output)

Solution (Python):
n = int(input())
for i in range(n // 2):
    print(i + 1, end=' ')
    print(n - i, end=' ')
if n % 2 != 0:
    print(n // 2 + 1)