题解 P17204 「DLESS-6」XOR and MEX
前言
暴力 + 剪枝甚至最大点才 1.19s。
题意
给定长度为
求:
思路
Sov.1—暴力枚举
显然不行,复杂度
Sov.2—缩小范围
不难发现,取
因此只需要枚举
Sov.3—再缩范围
实际上,最优的
经实验表明,枚举
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, m = 0;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());
while (m < a.size() && a[m] == m) {
m++;
}
int ans = m;
for (int x = 1; x <= min(m, 256); x++) {
int k = 0;
while (1) {
if (x + k >= ans) {
break;
}
if (!binary_search(a.begin(), a.end(), k ^ x)) {
ans = x + k;
break;
}
k++;
}
}
cout << ans << endl;
}
return 0;
}