-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxv.cpp
More file actions
70 lines (60 loc) · 1.41 KB
/
mxv.cpp
File metadata and controls
70 lines (60 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<iostream>
#include<vector>
#include<algorithm>
#include"../common/common.h"
using namespace std;
int findMinXor(vector<int>& A);
int findMinXorOpt(vector<int>& A);
int findMinXorOpt2(vector<int>& A);
int findMinXor(vector<int>& A) {
int N = A.size(), minXor = A[0] ^ A[1];
for (int x = 0; x < N; x++)
{
for (int y = x + 1; y < N; y++)
{
minXor = _min((A[x] ^ A[y]), minXor);
}
}
return minXor;
}
int findMinXorOpt(vector<int>& A) {
int N = A.size();
vector<int> PXOR(N, 0);
PXOR[0] = A[0]^A[1];
for (int x = 1; x < N; x++)
{
PXOR[x] = _min(PXOR[x - 1], A[x]);
}
long minXor = PXOR[0];
for (int i=1;i<N;i++)
{
minXor = _min(minXor, PXOR[i]);
}
return minXor;
}
int findMinXorOpt2(vector<int>& A) {
int N = A.size();
vector<int> SA(N, 0);
for (int i = 0; i < N; i++)
{
SA[i] = A[i];
}
sort(SA.begin(), SA.end());
long minXor = SA[0] ^ SA[1];
for (int i = 0; i+1 < N; i++)
{
minXor = _min(minXor, (SA[i] ^ SA[i + 1]));
}
return minXor;
}
int main()
{
cout << "hello min XOR";
vector<int> A = { 492416,275153,684032,319360,543232,804480,525824,671825,1036753,940625,909521,405120,1076689,80081,57856,1000145,13649 };
vector<int> C = { 0, 2, 5, 7 ,1};
vector<int> B = { 0, 4, 7, 9 };
cout << "minXor : " << findMinXorOpt2(A) << endl;
cout << "minXor : " << findMinXorOpt2(B) << endl;
cout << "minXor : " << findMinXorOpt2(C) << endl;
return 0;
}