http://www.lydsy.com/JudgeOnline/problem.php?id=3668
https://www.luogu.org/problemnew/show/P2114
显然的贪心,对于二进制下的每一位考虑是否放1,从最高位开始放,这样就能保证最大化答案。
判断是否放1那当然是用防御门挨个算就行啦。
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cctype>
using namespace std;
const int N=1e5+;
struct data{
int op,k;
}qry[N];
char s[];
int n,m;
int suan(int a){
for(int i=;i<=n;i++){
if(qry[i].op==)a&=qry[i].k;
if(qry[i].op==)a|=qry[i].k;
if(qry[i].op==)a^=qry[i].k;
}
return a;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
scanf("%s%d",s,&qry[i].k);
if(s[]=='A')qry[i].op=;
if(s[]=='O')qry[i].op=;
if(s[]=='X')qry[i].op=;
}
int ans=;
for(int i=;i>=;i--){
if(ans+(<<i)>m)continue;
if(suan(ans)<suan(ans+(<<i)))ans+=(<<i);
}
printf("%d\n",suan(ans));
return ;
}
+++++++++++++++++++++++++++++++++++++++++++
+本文作者:luyouqi233。 +
+欢迎访问我的博客:http://www.cnblogs.com/luyouqi233/+
+++++++++++++++++++++++++++++++++++++++++++