当前位置:网站首页>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
. env. XXX file, with constant, but undefined
Door level modeling - after class exercises
[understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing
S32Kxxx bootloader之UDS bootloader
Kubernetes resource object introduction and common commands (III)
Know --matplotlib
Multi table operation - one to one, one to many and many to many
2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍
随机推荐
Material Design组件 - 使用BottomSheet展现扩展内容(一)
jpa手写sql,用自定义实体类接收
RPA tutorial 01: Excel automation from introduction to practice
小程序表单校验封装
Is it safe to buy funds on Great Wall Securities?
S32Kxxx bootloader之UDS bootloader
【必会】BM41 输出二叉树的右视图【中等+】
How to solve the image pop-up problem when pycharm calls Matplotlib to draw
【无标题】
多表操作-一对一,一对多与多对多
ARP message header format and request flow
Know --matplotlib
TS initial use, TS type
PyTorch学习记录
求逆序数的三个方法
Redis AOF日志
记录一下大文件上传偶然成功偶然失败问题
Windows 7 install MySQL error: 1067
电商RPA机器人,助力品牌电商抢立流量高点
Algolia's search needs are almost closed