当前位置:网站首页>起床困难综合症(按位贪心)
起床困难综合症(按位贪心)
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;
}
边栏推荐
- Deep learning | three concepts: epoch, batch, iteration
- Relatively easy to understand PID understanding
- sql 优化
- What are the common types of points mall games?
- Redis AOF log
- Resumption of attack and defense drill
- How to realize parallel replication in MySQL replication
- excel如何打开100万行以上的csv文件
- 有没有一段代码,让你为人类的智慧所折服
- 【CMake】Qt creator 里面的 cmake 配置
猜你喜欢

Learn online case practice
![Various global files related to [.Net core] program](/img/89/32623abf30d3dc92a3cdb1710a624f.png)
Various global files related to [.Net core] program

Is there a piece of code that makes you convinced by human wisdom

De PIP. Interne. CLI. Main Import main modulenotfounderror: No module named 'PIP'

使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object

Development trend and future direction of neural network Internet of things

【.Net Core】程序相关各种全局文件

使用VB.net将PNG图片转成icon类型图标文件

【QT】Qt 使用MSVC2017找不到编译器的解决办法
![[QT] solve the problem that QT MSVC 2017 cannot compile](/img/35/e458fd437a0bed4bace2d6d65c9ec8.png)
[QT] solve the problem that QT MSVC 2017 cannot compile
随机推荐
Development trend and future direction of neural network Internet of things
软件架构的本质
- Oui. Env. Fichier XXX, avec constante, mais non spécifié
Zero foundation tutorial of Internet of things development
Depth first search and breadth first search of graph traversal
Deep learning | three concepts: epoch, batch, iteration
[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler
电商RPA机器人,助力品牌电商抢立流量高点
De PIP. Interne. CLI. Main Import main modulenotfounderror: No module named 'PIP'
cookie、session、tooken
algolia 搜索需求,做的快自闭了...
Distance measurement - Hamming distance
ADO. Net SqlConnection object usage summary
Notblank and notempty
Why does blocprovider feel similar to provider?
How to display real-time 2D map after rviz is opened
TS initial use, TS type
在长城证券上买基金安全吗?
Write some suggestions to current and future doctoral students to sort out and share
Practical application and extension of plain framework