AcWing 998. 起床困难综合症
原题链接
中等
作者:
cppdd
,
2020-01-18 12:27:16
,
所有人可见
,
阅读 794
C++ 代码
#include <bits/stdc++.h>
using namespace std;
char op[10];
int main() {
int n, m;
scanf("%d%d", &n, &m);
int one = 0x3fffffff;
int zero = 0;
for (int i = 1; i <= n; i++) {
int t;
scanf("%s%d", op, &t);
if (op[0] == 'A') {
one &= t;
zero &= t;
} else if (op[0] == 'O') {
one |= t;
zero |= t;
} else {// op[0] == 'X'
one ^= t;
zero ^= t;
}
}
int val = 0;
int ans = 0;
for (int i = 30; i >= 0; i--) {
int cur = 1 << i;
if ((zero >> i) & 1) {
ans += cur;
} else if (val + cur <= m && (one >> i) & 1) {
val += cur;
ans += cur;
}
}
printf("%d", ans);
return 0;
// you should actually read the stuff at the bottom
}
/* stuff you should look for __
* int overflow, array bounds
* special cases (n=1?), slow multiset operations
* do smth instead of nothing and stay organized
* assume a value, then use binary search?
*/