当前位置:网站首页>起床困难综合症(按位贪心)
起床困难综合症(按位贪心)
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;
}
边栏推荐
- Regular expression collection
- PyCharm调用matplotlib绘图时图像弹出问题怎么解决
- 2021 robocom world robot developer competition - semi finals of higher vocational group
- [untitled]
- 力扣今日题-241. 为运算表达式设计优先级
- Resumption of attack and defense drill
- BlocProvider为什么感觉和Provider很相似?
- 第六章 数据流建模
- Why does blocprovider feel similar to provider?
- Li Kou today's question -241 Design priorities for operational expressions
猜你喜欢

Why does blocprovider feel similar to provider?

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

Matplotlib common charts

What professional classification does the application of Internet of things technology belong to

Deep learning | three concepts: epoch, batch, iteration

有没有一段代码,让你为人类的智慧所折服

Distance measurement - Hamming distance

Practical application and extension of plain framework

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

Linux foundation - centos7 offline installation of MySQL
随机推荐
【.Net Core】程序相关各种全局文件
Redis RDB快照
Learn online case practice
2021 robocom world robot developer competition - preliminary competition of higher vocational group
ADO.NET之sqlCommand对象
Chapter 6 data flow modeling
小程序表单校验封装
cookie、session、tooken
Deep learning | three concepts: epoch, batch, iteration
Use pair to do unordered_ Key value of map
What are the common types of points mall games?
ADO. Net SqlDataAdapter object
Notes to problems - file /usr/share/mysql/charsets/readme from install of mysql-server-5.1.73-1 glibc23.x86_ 64 c
E-commerce RPA robot helps brand e-commerce to achieve high traffic
ConcurrentSkipListMap——跳表原理
How to realize parallel replication in MySQL replication
在长城证券上买基金安全吗?
【C#】依赖注入及Autofac
cookie、session、tooken
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS