当前位置:网站首页>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;
}
边栏推荐
- 2021 robocom world robot developer competition - semi finals of higher vocational group
- Material Design组件 - 使用BottomSheet展现扩展内容(一)
- Various global files related to [.Net core] program
- 2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
- Iota in golang
- 使用htaccess文件禁止目录里的脚本执行权限
- 哈工大《信息内容安全》课程知识要点和难点
- vs2015 AdminDeployment. xml
- PyTorch学习记录
- 起床困难综合症(按位贪心)
猜你喜欢
Redis AOF log
字典、哈希表、数组的概念
[es practice] safe operation mode on ES
Development trend and future direction of neural network Internet of things
.env.xxx 文件,加了常量,卻undefined
BlocProvider为什么感觉和Provider很相似?
Chapter 6 data flow modeling
notBlank 和 notEmpty
Selectively inhibiting learning bias for active sampling
【CMake】Qt creator 里面的 cmake 配置
随机推荐
openwrt 开启KV漫游
Relatively easy to understand PID understanding
13 MySQL constraint
ARP message header format and request flow
notBlank 和 notEmpty
JPA handwritten SQL, received with user-defined entity classes
Multi table operation - one to one, one to many and many to many
Is there a piece of code that makes you convinced by human wisdom
[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler
Timer和ScheduledThreadPoolExecutor的区别
Key points and difficulties of the course "information content security" at Harbin Institute of Technology
The third part of the construction of the defense system of offensive and defensive exercises is the establishment of a practical security system
Redis AOF日志
Yunxin small class | common cognitive misunderstandings in IM and audio and video
URL introduction
Why does blocprovider feel similar to provider?
求逆序数的三个方法
Material Design组件 - 使用BottomSheet展现扩展内容(一)
[LeetCode] 最后一个单词的长度【58】
Know --matplotlib