当前位置:网站首页>起床困难综合症(按位贪心)
起床困难综合症(按位贪心)
2022-07-01 23:49:00 【why151】
题目描述:

主要思路:
本题主要考察贪心与位运算。
a1=0:
在穿越完保护罩之后,第i位=1,那么ans可以直接+1<<i,不需要满足其他条件。
a2=0:
在穿越完保护罩之后,第i位=1,需要满足(1<<i)<=m,因为需要一开始的x的第i位=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;
}
边栏推荐
- PyTorch学习记录
- How to realize parallel replication in MySQL replication
- Oracle中已定义者身份执行函数AUTHID DEFINER与Postgresql行为的异同
- VIM color the catalogue
- Is it safe to buy funds on Great Wall Securities?
- Write some suggestions to current and future doctoral students to sort out and share
- 【C#】依赖注入及Autofac
- 2021 RoboCom 世界机器人开发者大赛-高职组复赛
- 【QT】对于Qt MSVC 2017无法编译的问题解决
- Why does blocprovider feel similar to provider?
猜你喜欢

【必会】BM41 输出二叉树的右视图【中等+】

使用VB.net将PNG图片转成icon类型图标文件
![Various global files related to [.Net core] program](/img/89/32623abf30d3dc92a3cdb1710a624f.png)
Various global files related to [.Net core] program

PyCharm调用matplotlib绘图时图像弹出问题怎么解决

2021 RoboCom 世界机器人开发者大赛-高职组复赛

Pytorch learning record

What category does the Internet of things application technology major belong to

Relatively easy to understand PID understanding

Learn online case practice

Know --matplotlib
随机推荐
【QT】對於Qt MSVC 2017無法編譯的問題解决
【QT】QtCreator卸载与安装(非正常状态)
ADO. Net SqlCommand object
Deep learning | three concepts: epoch, batch, iteration
vs2015 AdminDeployment. xml
SQL optimization
股票开户哪个证券公司最好,有安全保障吗
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
2021 robocom world robot developer competition - preliminary competition of undergraduate group
Why is PHP called hypertext preprocessor
Why does blocprovider feel similar to provider?
The best smart home open source system in 2022: introduction to Alexa, home assistant and homekit ecosystem
MySQL: the difference between insert ignore, insert and replace
学成在线案例实战
PostgreSQL notes (10) dynamically execute syntax parsing process
正则表达式收集
Windows 7 install MySQL error: 1067
2021 RoboCom 世界机器人开发者大赛-高职组初赛
Anomaly-Transformer (ICLR 2022 Spotlight)复现过程及问题
kubernetes资源对象介绍及常用命令(三)