-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.cpp
44 lines (44 loc) · 844 Bytes
/
C.cpp
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
#include <bits/stdc++.h>
using namespace std;
const int bit = 30;
const int maxn = 2e5 + 10;
int a[maxn];
struct node {
node *a[2];
node () {
a[0] = a[1] = NULL;
}
} *root;
void insert(int val) {
node* cur = root;
for(int i = bit; i >= 0; i--) {
int bit = (val >> i) & 1;
if(cur -> a[bit] == NULL) {
cur -> a[bit] = new node();
}
cur = cur -> a[bit];
}
}
int query(int val) {
node *cur = root;
int cnt = 1;
for(int i = bit; i >= 0; i--) {
int bit = (val >> i) & 1;
if(cur -> a[bit ^ 1]) ++cnt;
cur = cur -> a[bit];
}
return cnt;
}
int main() {
int n;
scanf("%d", &n);
root = new node();
for(int i = 0; i < n; i++) {
scanf("%d", &a[i]);
insert(a[i]);
}
int ret = 0;
for(int i = 0; i < n; i++) ret = max(ret, query(a[i]));
printf("%d\n", n - ret);
return 0;
}