CF1299A.Anu Has a Function
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Anu has created her own function f: f(x,y)=(x∣y)−y where ∣ denotes the bitwise OR operation. For example, f(11,6)=(11∣6)−6=15−6=9. It can be proved that for any nonnegative numbers x and y value of f(x,y) is also nonnegative.
She would like to research more about this function and has created multiple problems for herself. But she isn't able to solve all of them and needs your help. Here is one of these problems.
A value of an array [a1,a2,…,an] is defined as f(f(…f(f(a1,a2),a3),…an−1),an) (see notes). You are given an array with not necessarily distinct elements. How should you reorder its elements so that the value of the array is maximal possible?
Anu 定义了她自己的函数 f:f(x,y)=(x∣y)−y,其中 ∣ 表示按位或运算。例如,f(11,6)=(11∣6)−6=15−6=9。可以证明:对任意非负整数 x 和 y,f(x,y) 的值也必为非负数。
她希望进一步研究该函数,并为自己设计了多个相关问题。但她无法全部解决,因此需要你的帮助。以下是这些问题之一。
一个数组 [a1,a2,…,an] 的值定义为 f(f(…f(f(a1,a2),a3),…an−1),an)(参见注释)。给定一个元素不一定互异的数组,请问应如何重排其元素,使得该数组的值达到最大?
输入格式
The first line contains a single integer n (1≤n≤105).
The second line contains n integers a1,a2,…,an (0≤ai≤109). Elements of the array are not guaranteed to be different.
第一行包含一个整数 n(1≤n≤105)。
第二行包含 n 个整数 a1,a2,…,an(0≤ai≤109)。数组中的元素不一定互不相同。
输出格式
Output n integers, the reordering of the array with maximum value. If there are multiple answers, print any.
输出 n 个整数,即该数组的一个重排,使其值最大。如果存在多个答案,输出任意一个即可。
输入输出样例
输入#1
4 4 0 11 6
输出#1
11 6 4 0
输入#2
1 13
输出#2
13
说明/提示
In the first testcase, value of the array [11,6,4,0] is f(f(f(11,6),4),0)=f(f(9,4),0)=f(9,0)=9.
[11,4,0,6] is also a valid answer.
在第一个测试用例中,数组 [11,6,4,0] 的值为 f(f(f(11,6),4),0)=f(f(9,4),0)=f(9,0)=9。
[11,4,0,6] 也是一个合法的答案。
输入解题思路,AI测评打分。不知道怎么写?