日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #618 (Div. 2)-C. Anu Has a Function

發布時間:2023/12/15 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #618 (Div. 2)-C. Anu Has a Function 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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?

Input

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.Output Output n integers, the reordering of the array with maximum value. If there are multiple answers, print any.

Examples
inputCopy

4 4 0 11 6

outputCopy

11 6 4 0

inputCopy

1 13

outputCopy

13

Note

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.

我們把a|b-b換成 a-a&b,也就是說使得a&b最小,那我們考慮什么時候最大,即所有數的最高位,只有一個為1不然一定在運算的過程中被削去,那么這個題就可以改成,在32位中找某一位只有一個數是1的那一個數,讓他當第一。因為其余都會抵消。如果不存在,那么怎樣輸出都是0

#include <bits/stdc++.h> using namespace std; const int N = 100003; int n, a[N]; int main() {cin >> n;for (int i = 1; i <= n; ++i){cin >> a[i];}for (int j = 30; ~j; --j){int cnt = 0, p;for (int i = 1; i <= n; ++i)if ((a[i] >> j) & 1)++cnt, p = i;if (cnt == 1){printf("%d ", a[p]);for (int k = 1; k <= n; ++k)if (k != p)printf("%d ", a[k]);return 0;}}cout<<endl<<endl;for (int i = 1; i <= n; ++i)printf("%d ", a[i]); }

總結

以上是生活随笔為你收集整理的Codeforces Round #618 (Div. 2)-C. Anu Has a Function的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。