当前位置:网站首页>起床困难综合症(按位贪心)
起床困难综合症(按位贪心)
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;
}
边栏推荐
- 【无标题】
- Matplotlib common charts
- Concepts of dictionary, hash table and array
- 【QT】测试Qt是否能连接上数据库
- .env.xxx 文件,加了常量,卻undefined
- 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
- 第六章 数据流建模
- 2021 RoboCom 世界机器人开发者大赛-高职组复赛
- Postgresql源码(58)元组拼接heap_form_tuple剖析
- E-commerce RPA robot helps brand e-commerce to achieve high traffic
猜你喜欢

Using uni simple router, dynamically pass parameters typeerror: cannot convert undefined or null to object

Matplotlib common charts

Overview of edge calculation

使用 pair 做 unordered_map 的键值

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

Algolia's search needs are almost closed

Redis RDB快照

Key points of security agreement

ARP message header format and request flow

Practical application and extension of plain framework
随机推荐
Redis 主从同步
How excel opens CSV files with more than one million lines
深度学习 | 三个概念:Epoch, Batch, Iteration
2021 robocom world robot developer competition - semi finals of higher vocational group
Deep learning | three concepts: epoch, batch, iteration
. env. XXX file, with constant, but undefined
BlocProvider为什么感觉和Provider很相似?
ADO. Net SqlCommand object
Windows 7 install MySQL error: 1067
[LeetCode] 最后一个单词的长度【58】
golang中的iota
在长城证券上买基金安全吗?
Key points of security agreement
在代码中使用SqlCommand对象
2021 RoboCom 世界机器人开发者大赛-本科组初赛
多表操作-一对一,一对多与多对多
RPA tutorial 01: Excel automation from introduction to practice
【C#】依赖注入及Autofac
Depth first search and breadth first search of graph traversal
Overview of edge calculation