Title: Http://codeforces.com/contest/879/problem/C
Test instructions
There is a function that enters a positive integer x, passes N (N<5E5) operations, returns a positive integer with three operations, and XI (0~1023) ^ | &,. Now you are asked how the functions in the 5 operations function are the same as the N operations.
Analysis:
Each bit of x (0/1) is changed to (0/1) after n operations, so it can be constructed with and or XOR accordingly.
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <map
> #include <set> #include <queue> #include <cstdio> #include <cstring> #include <cmath>
using namespace Std;
const int n=1e3+9;
typedef long Long LL;
typedef pair<int,int> PII;
int n;
int bit0[11],bit1[11]; int OPR (char op,int bit, int b) {if (op== ' | ')
return bit|b;
else if (op== ' & ') return bit&b;
else return bit^b;
} int main () {scanf ("%d", &n);
for (int i=0;i<10;i++) bit0[i]=0,bit1[i]=1;
Char op;
int x;
for (int i=0;i<n;i++) {scanf ("%c%d", &op,&x); for (int j=0;j<10;j++) {int b=!!
(X & (1<<j));
BIT0[J] = OPR (op,bit0[j],b);
BIT1[J] = OPR (op,bit1[j],b);
}} int aand=1023,aor=0,axor=0;
for (int i=0;i<10;i++) {int b=1<<i;
if (bit0[i]==1 && bit1[i]==1) AOR |= B; ELSE if (bit0[i]==0 && bit1[i]==0) aand &= ~b;
else if (bit0[i]==1 && bit1[i]==0) axor |= b;
} printf ("3\n"); printf ("|
%d\n ", AOR);
printf ("&%d\n", aand);
printf ("^%d\n", axor);
return 0;
}