当前位置:网站首页>牛客练习赛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';
}
边栏推荐
- 022 basics of C language: C memory management and C command line parameters
- 011 C language basics: C scope rules
- 016 C语言基础:C语言枚举类型
- ES6 0622 III
- 面对AI人才培养的“产学研”鸿沟,昇腾AI如何做厚产业人才黑土地?
- Fplan powerplan instance
- 笔记本电脑没有WiFi选项 解决办法
- Microservice system design -- microservice monitoring and system resource monitoring design
- 微服务系统设计——服务熔断和降级设计
- Golang Hello installation environment exception [resolved]
猜你喜欢

微服务系统设计——消息缓存服务设计

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

Kotlin compose implicitly passes the parameter compositionlocalprovider

PostgreSQL基础命令教程:创建新用户admin来访问PostgreSQL

Redis高可用集群(哨兵、集群)

为什么 C# 访问 null 字段会抛异常?

Système de collecte des journaux

Microservice system design - service fusing and degradation design

Microservice system design -- Distributed timing service design

Penetration test - directory traversal vulnerability
随机推荐
[BJDCTF2020]The mystery of ip
Log collection system
QChart笔记2: 添加鼠标悬停显示
Kotlin Compose 隐式传参 CompositionLocalProvider
Kotlin compose compositionlocalof and staticcompositionlocalof
015 basics of C language: C structure and common body
快速排序(非遞歸)和歸並排序
Installation of low code development platform nocobase
006 C语言基础:C存储类
018 C语言基础:C文件读写
Redis高可用集群(哨兵、集群)
Tri rapide (non récursif) et tri de fusion
快速排序(非递归)和归并排序
Office VR porn, coquettish operation! The father of Microsoft hololens resigns!
Microservice system design -- service registration, discovery and configuration design
Argo workflows - getting started with kubernetes' workflow engine
微服务系统设计——消息缓存服务设计
PostgreSQL basic command tutorial: create a new user admin to access PostgreSQL
Kotlin compose implicitly passes the parameter compositionlocalprovider
高等数学(第七版)同济大学 习题1-10 个人解答