当前位置:网站首页>牛客练习赛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';
}
边栏推荐
- Qchart note 2: add rollover display
- Microservice system design -- distributed lock service design
- Fplan power planning
- Building lightweight target detection based on mobilenet-yolov4
- Système de collecte des journaux
- 微服务系统设计——服务熔断和降级设计
- math_ Number set (number set symbol) and set theory
- leetcode-20. Valid parentheses -js version
- 021 basics of C language: recursion, variable parameters
- 013 basics of C language: C pointer
猜你喜欢
![[array]bm94 rainwater connection problem - difficult](/img/2b/1934803060d65ea9139ec489a2c5f5.png)
[array]bm94 rainwater connection problem - difficult

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

面对AI人才培养的“产学研”鸿沟,昇腾AI如何做厚产业人才黑土地?

【B站UP DR_CAN学习笔记】Kalman滤波2

MySql最详细的下载教程

math_数集(数集符号)和集合论

WPF 开源控件库Extended WPF Toolkit介绍(经典)

golang hello 安装环境异常【已解决】
![[BJDCTF2020]The mystery of ip](/img/f8/c3a7334252724635d42c8db3d1bbb0.png)
[BJDCTF2020]The mystery of ip

百度飞桨“万有引力”2022首站落地苏州,全面启动中小企业赋能计划
随机推荐
Tsinghua University open source software mirror website
Chapter 2 Introduction to key technologies
Facing the "industry, University and research" gap in AI talent training, how can shengteng AI enrich the black land of industrial talents?
Log collection system
【C语言】关键字的补充
016 C language foundation: C language enumeration type
微服务系统设计——服务注册与发现和配置设计
010 C language foundation: C function
011 C language basics: C scope rules
Qchart note 2: add rollover display
Microservice system design -- unified authentication service design
013 C语言基础:C指针
快速排序(非遞歸)和歸並排序
010 C语言基础:C函数
The most detailed download tutorial of MySQL
Kotlin Compose compositionLocalOf 与 staticCompositionLocalOf
halcon常用仿射变换算子
跟着BUU学习Crypto(周更)
百度飞桨“万有引力”2022首站落地苏州,全面启动中小企业赋能计划
Microservice system design -- microservice monitoring and system resource monitoring design