首页 > 试题广场 >

Permuting cows

[编程题]Permuting cows
Niuniu likes cows. He has n cows in his farm. He loves the cows very much, but the cows seem unhappy. Niuniu figures out why this happens. The cows are arranged in a sequence. Two cows may become unhappy when they are adjacent in the sequence. Every cow has a characteristic value, named vi. The unhappiness between cow i and i+1 is defined as vi xor vi+1. (xor is exclusive OR) Niuniu wants the largest unhappiness between each pair of adjacent cows to be as low as possible. You need to tell him a permutation pi, so that when the i-th position is the pi-th cow in the new sequence, the largest unhappiness is as low as possible. Among all the permutations, you need to tell him the lexicographically smallest one.

输入描述:
The first line contains one integer n, which is the number of cows. The second line contains n integers, v1 v2 … vn, separated by a space. (2 ≤ n ≤ 300000, 0 ≤ vi ≤ 1000000000)


输出描述:
Print a single line with n numbers, which means the permutation.
示例1

输入

8
1 9 2 6 0 8 1 7

输出

1 2 6 5 3 4 7 8

备注:
This problem contains a large number of testcases.  Please, check your code carefully before you submit and wait patiently for the result.

这道题你会答吗?花几分钟告诉大家答案吧!

问题信息

难度:
0条回答 3浏览

热门推荐

通过挑战的用户

查看代码
Permuting cows