CF1466C题解
看到最小异或值可以想到 trie 树,但是删除操作实现过于困难,正难则反,考虑求最大保留数。
设 trie 树 上以
当
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int const N = 3e7 + 5;
inline int read() {
int res = 0, f = 1; char c = getchar();
while(!isdigit(c)) {
if(c == '-') f = -1;
c = getchar();
}
while(isdigit(c)) {
res = res * 10 + c - '0';
c = getchar();
}
return res * f;
}
class Tire {
int ch[N][2], tot;
public:
inline void insert(int const &val) {
int p = 0;
for(int i = 30; ~i; -- i) {
bool x = (val >> i) & 1;
if(!ch[p][x]) ch[p][x] = ++ tot;
p = ch[p][x];
}
}
int dfs(int x) {
if(!ch[x][0] and !ch[x][1]) return 1;
if(!ch[x][0]) return dfs(ch[x][1]);
if(!ch[x][1]) return dfs(ch[x][0]);
return max(dfs(ch[x][0]), dfs(ch[x][1])) + 1;
}
}t;
int main() {
int n = read();
for(int i = 1; i <= n; ++ i)
t.insert(read());
printf("%d\n", n - t.dfs(0));
return 0;
}