求助,玄关
  • 板块灌水区
  • 楼主swonkenon
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/1/24 14:36
  • 上次更新2024/1/24 14:55:42
查看原帖
求助,玄关
729806
swonkenon楼主2024/1/24 14:36

P2114 [NOI2014] 起床困难综合症

这个题我的代码 #6 WA 了,求调

#include <bits/stdc++.h>
using namespace std;

int n, m, ans, x, a1, a2 = -1, p[50];
string s;

int main() {
	scanf("%d%d", &n, &m);
	while(n--) {
		cin >> s >> x;
		if(s == "AND") a1 &= x, a2 &= x;
		if(s == "XOR") a1 ^= x, a2 ^= x;
		if(s == "OR") a1 |= x, a2 |= x;
	}
	p[0] = 1;
	for(int i = 1; i <= 30; i++)
		p[i] = p[i-1] * 2;
	for(int i = 29; i >= 0; i--) {
		if((a1>>i) % 2 == 1) ans += p[i];
		else if((a2>>i) % 2 == 1 && p[i] <= m) {
			ans += p[i];
			m -= p[i];
		}
	}
	printf("%d\n", ans);
	return 0;
}
2024/1/24 14:36
加载中...