当前位置:网站首页>牛客-练习赛101-推理小丑
牛客-练习赛101-推理小丑
2022-07-01 23:49:00 【why151】
推理小丑
题目描述

主要思路:
这个题目主要是利用一种尝试的方法进行求解。
有高位到低位依次尝试。
如果高位可以不为1就满足<的话,那么高位就不要为1;
如果高位不为1就会出现>的话,那么高位一定为1;
如果出现=的情况的话,需要往后看,不行的话再为1。
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int n;
int a[N];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
int ans=0;
for(int i=30;i>=0;i--)
{
int now=ans;
bool flag;
for(int j=i-1;j>=0;j--)
{
now|=1<<j;
flag=1;
for(int k=1;k<n;k++) {
if((a[k]&now)>(a[k+1]&now))
{
flag=0;
break;
}
}
if(!flag) now^=1<<j;
}
flag=1;
for(int k=1;k<n;k++)
{
if((a[k]&now)>=(a[k+1]&now))
{
flag=0;
break;
}
}
if(!flag) ans|=1<<i;
}
cout<<ans<<endl;
return 0;
}
边栏推荐
- 使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object
- Material design component - use bottomsheet to show extended content (I)
- ADO.NET 之sqlConnection 对象使用摘要
- Door level modeling - after class exercises
- Key points of security agreement
- [QT] solve the problem that QT MSVC 2017 cannot compile
- 【CMake】Qt creator 里面的 cmake 配置
- Postgresql随手记(10)动态执行EXECUTING语法解析过程
- MySQL: the difference between insert ignore, insert and replace
- 【C#】依赖注入及Autofac
猜你喜欢
随机推荐
安全协议重点
Resumption of attack and defense drill
Redis RDB快照
2021 robocom world robot developer competition - semi finals of higher vocational group
vs2015 AdminDeployment.xml
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
What are the common types of points mall games?
深度学习 | 三个概念:Epoch, Batch, Iteration
How to realize parallel replication in MySQL replication
cookie、session、tooken
2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍
[untitled]
在代码中使用SqlCommand对象
Know --matplotlib
Kubernetes resource object introduction and common commands (III)
[QT] qtcreator uninstall and installation (abnormal state)
Use pair to do unordered_ Key value of map
The essence of software architecture
E-commerce RPA robot helps brand e-commerce to achieve high traffic
攻防演练复盘









