当前位置:网站首页>Codeforces Global Round 21 A. NIT orz!
Codeforces Global Round 21 A. NIT orz!
2022-07-15 19:32:00 【追烽】
https://codeforces.com/contest/1696/problem/A
标签
位运算
题意
给定长度为 n 的数组 a, 进行以下 0 到任意次操作:
选择任意 ai, 使 ai = ai | z,z = ai & z.
输出任意次操作后数组 a 的最大值.
思路
ai = ai | z, ai 不严格递增
同理, z 不严格递减
如果找到一个 a[x1], 使 a[ans] = a[x1] | z 最大, 那么当 z &= a[x1] (z 变小) 时, 不可能找到其他的 a[x2] 使 a[x2] |= z 大于 a[ans].
如果找到一个 a[x3], z[x3] != a[x1], 那么 a[x3] |= z 小于 a[ans], 此时 z &= a[x3] (z 变小) , 不可能找到其他的 a[x4] 使 a[x4] |= z 大于 a[ans].
综上, 操作只能进行至多 1 次, 即找到最佳的 a[i], 使 a[ans] = a[x1] | z 最大.
代码

#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
signed main(){
cin.tie(0)->sync_with_stdio(0);
int T;cin>>T;
while(T--){
int n,z;cin>>n>>z;
int ai,ans=0;
FOR(i,1,n){
cin>>ai;
ans=max(ans,ai|z);
}
cout<<ans<<'\n';
}
return 0;
}
边栏推荐
- Accumulate class hour experience and practice of children's programming
- Can SQL also play AI? you 're right! Mlops meetup V3 review openmlbd+sqlflow+byzer
- SQL也能玩转AI ?没错!MLOps Meetup V3 回顾|OpenMLBD+SQLFlow+Byzer
- Is it safe to open an account and speculate in stocks online at present?
- 请问政务网服务器的mysql数据已经与dataworks开通网络策略,但是测试还是说数据库测试连通性
- 设计稳定的微服务系统时不得不考虑的场景
- SQL也能做AI ?没错!MLOps Meetup V3 回顾|OpenMLBD+SQLFlow+Byzer
- 求助,更新到思源 v2.0.27,dark+ 主题自适应宽度问题
- 信息检索顶会SIGIR2022最佳论文奖出炉,墨尔本理工大学最佳论文,UMass大学等最佳短论文
- Role based security access control strategy for virtual machine in cloud environment
猜你喜欢
随机推荐
USB driver development process
Ubuntu 22.04 LTS 是目前最安全的版本的七大原因
Modify WiFi for Xiaomi camera
C writes the database connection mode to the configuration file
Codeforces Round #802 C. Helping the Nature
Unity Shader——CGInclude文件cginc
Grow up Summer Challenge | learn / create from the boss, and get CSDN gift bag, exclusive certificate of honor, commemorative T-shirt and medal!
一种指纹生物特征的隐私保护和认证方法
【C语言初阶】函数学习报告
[mt2126] Digital Games
Extension and expansion of steam classroom education concept
增额终身寿险收益怎么样?可以当养老理财产品吗?
HybridCLR——划时代的Unity原生C#热更新技术
User login and registration function with verification code
Network trusted identity authentication
Codeforces Round #804 C The Third Problem
[open source trusted privacy computing framework "argot"] ant announced the official open source for global developers
如何在dataworks写ADB的sql
internship:移动端源码的分析
【ARCGIS创建中国南海诸岛及九段线小图框】








