当前位置:网站首页>Difficult to get up syndrome (bit by bit greed)
Difficult to get up syndrome (bit by bit greed)
2022-07-01 23:52:00 【why151】
Title Description :
Main idea :
This topic mainly focuses on greed and bit operation .
a1=0:
After crossing the protective cover , The first i position =1, that ans Can directly +1<<i, No other conditions need to be met .
a2=0:
After crossing the protective cover , The first i position =1, Need to meet (1<<i)<=m, Because it needs to start x Of the i position =1.
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int a1=0,a2=-1;
for(int i=1;i<=n;i++)
{
string op;
int x;
cin>>op>>x;
if(op=="AND") a1&=x,a2&=x;
if(op=="OR") a1|=x,a2|=x;
if(op=="XOR") a1^=x,a2^=x;
}
int ans=0;
for(int i=0;i<30;i++)
{
if(a1>>i&1) ans|=1<<i;
else if(a2>>i&1)
{
if((1<<i)<=m)
{
ans|=1<<i;
m-=1<<i;
}
}
}
cout<<ans<<endl;
return 0;
}
边栏推荐
- 图的遍历之深度优先搜索和广度优先搜索
- Practical application and extension of plain framework
- 2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍
- [must] bm41 output the right view of the binary tree [medium +]
- Pytorch learning record
- 【CMake】Qt creator 里面的 cmake 配置
- Learn online case practice
- ARP message header format and request flow
- 2021 RoboCom 世界机器人开发者大赛-本科组初赛
- Windows 7 安装MYSQL 错误:1067
猜你喜欢
Know --matplotlib
. env. XXX file, with constant, but undefined
PostgreSQL source code (57) why is the performance gap so large in hot update?
学成在线案例实战
Concepts of dictionary, hash table and array
[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler
Using uni simple router, dynamically pass parameters typeerror: cannot convert undefined or null to object
边缘计算概述
起床困难综合症(按位贪心)
Notblank and notempty
随机推荐
常见的积分商城游戏类型有哪些?
golang中的iota
Leetcode (34) -- find the first and last positions of elements in a sorted array
学成在线案例实战
记录一下大文件上传偶然成功偶然失败问题
Redis AOF日志
2021 RoboCom 世界机器人开发者大赛-本科组初赛
Know --matplotlib
[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler
小程序表单校验封装
Deep learning | three concepts: epoch, batch, iteration
vs2015 AdminDeployment. xml
正则表达式收集
Redis RDB snapshot
起床困难综合症(按位贪心)
PostgreSQL source code (58) tuple splicing heap_ form_ Tuple analysis
Various global files related to [.Net core] program
【QT】QtCreator卸载与安装(非正常状态)
Windows 7 安装MYSQL 错误:1067
Postgresql随手记(10)动态执行EXECUTING语法解析过程