luogu2114 [NOI2014]起床困难综合症

大约是第一次做近几年NOI题(尽管是签到题)?
制作一个真值表,要是有哪一位原本是0但是能变成1那真是太好啦,要是有哪一位原来是1能变成1并且算上它不会超过m那也不错。

#include <iostream>
#include <cstdio>
using namespace std;
int zz1, zz2, n, m, t, ans;
char op[13];
int main(){
	cin>>n>>m;
	for(int i=0; i<=30; i++)
		zz1 |= 1<<i;
	for(int i=1; i<=n; i++){
		scanf("%s %d", op, &t);
		if(op[0]=='A'){
			zz1 &= t;
			zz2 &= t;
		}
		if(op[0]=='O'){
			zz1 |= t;
			zz2 |= t;
		}
		if(op[0]=='X'){
			zz1 ^= t;
			zz2 ^= t;
		}
	}
	for(int i=30; i>=0; i--){
		if(zz2&(1<<i))
			ans |= 1<<i;
		else if(zz1&(1<<i) && m>=(1<<i)){
			ans |= 1<<i;
			m -= 1<<i;
		}
	}
	cout<<ans<<endl;
	return 0;
}
原文地址:https://www.cnblogs.com/poorpool/p/8169036.html