Harmonious Lineup - Question 4 - 2526 Q2

Xem dạng PDF

Gửi bài giải

Điểm: 1,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Hà Minh Ngọc
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

A lineup of ~n~ performers is considered harmonious if it satisfies the following two conditions:

  • Each performer is assigned a unique number from ~1~ to ~n~, and every number in this range is used exactly once.
  • For any two performers standing at positions ~i~ and ~j~ (where ~0 \le i < j < n~), there must not be a performer standing between them at position ~k~ ~(i < k < j)~ whose assigned number is exactly the average of the numbers assigned to positions ~i~ and ~j~.
  • In other words, ~2\times number_k \neq number_i + number_j~

Given an integer ~n~, arrange the performers so that the lineup is harmonious. It is guaranteed that at least one valid arrangement exists for every valid ~n~.

Input:

  • A single integer ~n~.

    Output:

  • Output any valid beautiful permutation of size ~n~.

  • The result must include each integer from ~1~ through ~n~ exactly once, with all values printed on a single line separated by spaces.

Example Input 1

4

Example Output 1

2 1 4 3

Example Input 2

5

Example Output 2

3 1 2 5 4

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.