起床困难综合症

本文介绍了一种利用二进制位操作技巧来模拟起床条件的算法,通过理解位运算符(AND, OR, XOR)如何影响二进制位,解决NowCoder竞赛中的起床问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

对于二进制的每一位,
初始为0, 结果为1 加上
初始为1, 结果为1 在条件内加上
初始为0, 结果为0 不变
初始为1, 结果为0 不变

// Problem: 起床困难综合症
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/996/E
// Memory Limit: 1048576 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
#include<list>
#include<unordered_map>
using namespace std;
#define lowbit(x) (x&-x)
#define pf(a) printf("%d\n",a)
#define mem(x,y) memset(x,y,sizeof(x))
#define dbg(x) cout << #x << " = " << x << endl
#define rep(i,l,r) for(int i = l; i <= r; i++)
#define fep(i,a,b) for(int i=b;i>=a;--i)
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e5+10;
int t, n, m;
char op[N];
int arr[N];

void solve()
{
	cin >> n >> m;
    bitset<40> none, alls;
    none.reset();
    alls.set();
	for(int i=1;i<=n;i++)
	{
		string op;
        cin >> op;
        cin >> t;
        if(op[0]=='A') none &= t, alls &= t;
        else if(op[0]=='O') none |= t, alls |= t;
        else none ^= t, alls ^= t;
	}
    int ans = 0;
    for(int i = 0; i < 30; i++)
    {
          if(none[i]==1) ans+=(1<<i);
		  else if(alls[i]==1&&m>=(1<<i)) ans+=(1<<i);
    }
    cout << ans;

}

int main()
{

	ios::sync_with_stdio(false);cin.tie(0);
		solve();
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值