当前位置:网站首页>牛客练习赛101-C 推理小丑---位运算+思维
牛客练习赛101-C 推理小丑---位运算+思维
2022-06-27 04:38:00 【WAWA源】

题目要求最小值,根据贪心思想,二进制表示情况下,高位1越少越好
#include<iostream>
using namespace std;
const int N = 100010;
int a[N];
int res=0;
int main()
{
int n;cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int j=30,i;j>=0;j--)//遍历每一位,假设这一位为0,如果不满足条件这一位必须选,为1
{
int t=res;
//看第j位为0的情况下是否满足条件
for(int k=j-1;k>=0;k--)
{
t|=1<<k;
//不满足break,这里必须是>号
for(i=1;i<n;i++)if((a[i]&t)>(a[i+1]&t))break;
//不满足证明这一位不能为1,异或一下变为原值
if(i!=n)t^=1<<k;
}
//判断是否满足,不满足证明第j位必须为1
for(i=1;i<n;i++)if((a[i]&t)>=(a[i+1]&t))break;
if(i!=n)res|=1<<j;
}
cout<<res<<'\n';
}
边栏推荐
- 【B站UP DR_CAN学习笔记】Kalman滤波1
- 015 basics of C language: C structure and common body
- nignx配置单ip限流
- QChart笔记2: 添加鼠标悬停显示
- halcon常用仿射变换算子
- Deep dive kotlin synergy (XV): Test kotlin synergy
- 009 C语言基础:C循环
- iOS开发:对于动态库共享缓存(dyld)的了解
- Almost because of json Stringify lost his bonus
- 021 basics of C language: recursion, variable parameters
猜你喜欢

百度飞桨“万有引力”2022首站落地苏州,全面启动中小企业赋能计划
![[array]bm94 rainwater connection problem - difficult](/img/2b/1934803060d65ea9139ec489a2c5f5.png)
[array]bm94 rainwater connection problem - difficult

快速掌握 ASP.NET 身份认证框架 Identity - 通过邮件重置密码

Microservice system design -- message caching service design

微服务系统设计——服务链路跟踪设计

Penetration test - directory traversal vulnerability

QChart笔记2: 添加鼠标悬停显示

2022-06-26:以下golang代码输出什么?A:true;B:false;C:编译错误。 package main import “fmt“ func main() { type

微服务系统设计——服务熔断和降级设计

Cultural tourism night tour | stimulate tourists' enthusiasm with immersive visual experience
随机推荐
The most detailed download tutorial of MySQL
011 C语言基础:C作用域规则
快速排序(非递归)和归并排序
Is the truth XX coming? Why are test / development programmers unwilling to work overtime? This is a crazy state
微服务系统设计——微服务调用设计
Chapter 2 Introduction to key technologies
Baidu PaddlePaddle's "universal gravitation" first stop in 2022 landed in Suzhou, comprehensively launching the SME empowerment plan
Microservice system design - service fusing and degradation design
渗透测试-文件上传/下载/包含
Fplan layout
Network structure and model principle of convolutional neural network (CNN)
Kotlin Compose compositionLocalOf 与 staticCompositionLocalOf
办公室VR黄片,骚操作!微软HoloLens之父辞职!
021 C语言基础:递归,可变参数
清华大学开源软件镜像站网址
微服务系统设计——服务链路跟踪设计
012 C语言基础:C数组
neo4j community与neo4j desktop冲突
In a sense, the Internet has become an incubator and a parent
[station B up dr_can learning notes] Kalman filter 3