Anu has created her own function ff: f(x,y)=(x|y)−yf(x,y)=(x|y)−y where || denotes the bitwise OR operation. For example, f(11,6)=(11|6)−6=15−6=9f(11,6)=(11|6)−6=15−6=9. It can be proved that for any nonnegative numbers xx and yy value of f(x,y)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][a1,a2,…,an] is defined as f(f(…f(f(a1,a2),a3),…an−1),an)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 nn (1≤n≤1051≤n≤105).
The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109). Elements of the array are not guaranteed to be different.
Output
Output nn integers, the reordering of the array with maximum value. If there are multiple answers, print any.
Examples
input
Copy
4
4 0 11 6
output
Copy
11 6 4 0
input
Copy
1
13
output
Copy
13
Note
In the first testcase, value of the array [11,6,4,0][11,6,4,0] is f(f(f(11,6),4),0)=f(f(9,4),0)=f(9,0)=9f(f(f(11,6),4),0)=f(f(9,4),0)=f(9,0)=9.
[11,4,0,6][11,4,0,6] is also a valid answer.
破题:如果所有数的的二进制的存在最高位和是1的话,将它输出,后面的直接输出就好。2 5 9 13 的话,输出2,后面的随便
#include
#include
#include
#include
#include
#include
//#include
#include
Guy-Manuel and Thomas are going to build a polygon spaceship.
You're given a strictly convex (i. e. no three points are collinear) polygon PP which is defined by coordinates of its vertices. Define P(x,y)P(x,y) as a polygon obtained by translating PP by vector (x,y)−→−−(x,y)→. The picture below depicts an example of the translation:
Define TT as a set of points which is the union of all P(x,y)P(x,y) such that the origin (0,0)(0,0) lies in P(x,y)P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y)(x,y) lies in TT only if there are two points A,BA,B in PP such that AB−→−=(x,y)−→−−AB→=(x,y)→. One can prove TT is a polygon too. For example, if PP is a regular triangle then TT is a regular hexagon. At the picture below PP is drawn in black and some P(x,y)P(x,y) which contain the origin are drawn in colored:
The spaceship has the best aerodynamic performance if PP and TT are similar. Your task is to check whether the polygons PP and TT are similar.
Input
The first line of input will contain a single integer nn (3≤n≤1053≤n≤105) — the number of points.
The ii-th of the next nn lines contains two integers xi,yixi,yi (|xi|,|yi|≤109|xi|,|yi|≤109), denoting the coordinates of the ii-th vertex.
It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon.
Output
Output "YES" in a separate line, if PP and TT are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower).
Examples
input
4 1 0 4 1 3 4 0 3
output
YES
input
3 100 86 50 0 150 0
output
nO
input
8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3
output
YES
Note
The following image shows the first sample: both PP and TT are squares. The second sample was shown in the statements.
破题:只要证明存在一组对边平行且相等就可以。(这个code比我那个好太多了)
#include
#define Rint register int
#define MP make_pair
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair pii;
template
inline void read(T &x){
int ch = getchar(); x = 0;
bool f = false;
while((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if(ch == '-'){f = true; ch = getchar();}
while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
if(f) x = -x;
}
const int N = 200003;
int n, x[N], y[N];
int main(){
read(n);
for(Rint i = 1;i <= n;++ i){
read(x[i]); read(y[i]);
}
if(n & 1) return puts("NO"), 0;
n >>= 1;
for(Rint i = 1;i <= n;++ i)
if(x[i + 1] - x[i] != x[i + n] - x[(i + n) % (2 * n) + 1] || y[i + 1] - y[i] != y[i + n] - y[(i + n) % (2 * n) + 1])
return puts("NO"), 0;
puts("YES");
}