Question: codeforces 165e-compatible numbers
Question: N numbers are given, and each number corresponds to a number in the current array that is equal to 0 in the AI operation. If not,-1 is output.
Analysis: Simple bit operation questions, technical questions
First of all, we know the nature of the operation, that is, it is 1 only when the value is 1 at the same time. If X & Y = 0, it is at least 0 if the value of X is 1 and all values of Y are 0, the rest is free. If it is 1, then Y = x ^ (1 <22)-1 ). However, this is not all. These bits may be 0, so we can enumerate these bits and process them.
Specific Code:
#include <cstdio>#include <cstring>#include <string>#include <iostream>#include <algorithm>#include <vector>#include <map>#include <queue>#define Del(a,b) memset(a,b,sizeof(a))using namespace std;const long long inf = 0x3f3f3f3f;const long long N = 1000100;const int M = 23;int a[N],dp[1<<23];int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); dp[a[i]^((1<<M)-1)] = a[i]; } for(int st = (1<<M)-1; st>=0 ;st--) { if(!dp[st]) { for(int i=0;i<M;i++) { if(dp[st|(1<<i)]) //枚举变化其他位 dp[st]=dp[st|(1<<i)]; } } } for(int i=0;i<n;i++) { if(dp[a[i]]) printf("%d",dp[a[i]]); else printf("-1"); printf("%c",i==(n-1)?'\n':' '); } return 0;}
Codeforces 165e-compatible numbers (bitwise Operation]