当前位置:网站首页>起床困难综合症(按位贪心)
起床困难综合症(按位贪心)
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;
}
边栏推荐
- Reproduction process and problems of analog transformer (ICLR 2022 Spotlight)
- Zero foundation tutorial of Internet of things development
- [LeetCode] 最后一个单词的长度【58】
- Future trend and development of neural network Internet of things
- VIM color the catalogue
- 攻防演练复盘
- 股票开户哪个证券公司最好,有安全保障吗
- SecurityUtils.getSubject().getPrincipal()为null的问题怎么解决
- ADO. Net SqlDataAdapter object
- Postgresql源码(57)HOT更新为什么性能差距那么大?
猜你喜欢
随机推荐
Material design component - use bottomsheet to show extended content (I)
mysql:insert ignore、insert和replace区别
Kubernetes resource object introduction and common commands (III)
RPA tutorial 01: Excel automation from introduction to practice
const // It is a const object...class nullptr_t
JPA handwritten SQL, received with user-defined entity classes
Using SqlCommand objects in code
URL introduction
SecurityUtils.getSubject().getPrincipal()为null的问题怎么解决
golang中的iota
excel如何打开100万行以上的csv文件
【C#】依赖注入及Autofac
How to realize parallel replication in MySQL replication
【QT】QtCreator卸载与安装(非正常状态)
Notes to problems - file /usr/share/mysql/charsets/readme from install of mysql-server-5.1.73-1 glibc23.x86_ 64 c
Is there a piece of code that makes you convinced by human wisdom
Door level modeling - after class exercises
ADO. Net SqlDataAdapter object
华为HMS Core携手超图为三维GIS注入新动能
2021 robocom world robot developer competition - preliminary competition of higher vocational group


![[es practice] safe operation mode on ES](/img/3f/fa28783770098ff10bffeccd64fe51.png)





