A bunch of nonsense ..
Given N operations (and, Or, different or ~ Select a number in m to maximize the value after N operations.
A great deal of water, such as soil, such as iron ..
This Nima is simply a question of water. We can discuss the following three situations when selecting each digit of a number:
1. When this bit is set to 0, the result obtained after N operations is set to 1. This is the ideal case. You must select 0.
2. Case 1 does not meet the requirement. If this parameter is set to 1, 1 is obtained after N operations and the value after 1 does not exceed M. In this case, we also select 1.
3. If the preceding two conditions are not met, the bitwise 0 must be smaller than the bitwise 1, which is more difficult than M.
So the question goes.
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define M 100100using namespace std;struct abcd{ int p,x; int cross(int y) { if(p==0) return x&y; if(p==1) return x|y; return x^y; }}a[M];int n,m;char s[100];int cross(int x){ int i; for(i=1;i<=n;i++) x=a[i].cross(x); return x;}int main(){ int i,ans=0,now; cin>>n>>m; for(i=1;i<=n;i++) { scanf("%s",s); if(s[0]=='A') a[i].p=0; else if(s[0]=='O') a[i].p=1; else a[i].p=2; scanf("%d",&a[i].x); } for(now=1;now<=m;now<<=1); for(now>>=1;now;now>>=1) { if(cross(0)&now) continue; if(ans+now<=m&&cross(now)&now) ans+=now; } printf("%d\n",cross(ans));}
Bzoj 3668 noi2014 getting up difficult syndrome greedy