CF165E Compatible Numbers
作者:互联网
solution
若 \(a\& b = 0\),设 \(c\) 为 \(a\) 中去掉几个 \(1\)。
则 \(c \& b = 0\)。
直接 \(O(n)\) 递推就好了。
\(f[i | (1 << j)] = f[i]\)
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int read() {
int x = 0, f = 1; char c = getchar();
while(c < '0' || c > '9') {if (c == '-') f = -1;c = getchar();}
while(c <= '9' && c >= '0') {x = x * 10 + c - '0';c = getchar();}
return x * f;
}
int f[1 << 23], n, a[MAXN];
int main() {
n = read();
memset(f, -1, sizeof f);
for (int i = 1; i <= n; i++) {
a[i] = read();
f[a[i] ^ ((1 << 23) - 1)] = a[i];
}
for (int i = (1 << 23) - 1; i; i--)
for (int j = 0; j < 23; j++)
if(f[i | (1 << j)] != -1) f[i] = f[i | (1 << j)];
for (int i = 1; i <= n; i++) cout<<f[a[i]]<<" ";
return 0;
}
标签:char,const,int,Compatible,while,Numbers,1e6,CF165E,getchar 来源: https://www.cnblogs.com/Arielzz/p/15488226.html