当前位置:网站首页>牛客-练习赛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;
}
边栏推荐
- Why is PHP called hypertext preprocessor
- Distance measurement - Hamming distance
- notBlank 和 notEmpty
- TS initial use, TS type
- Use vb Net to convert PNG pictures into icon type icon files
- 小程序表单校验封装
- BlocProvider为什么感觉和Provider很相似?
- [understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing
- 北京炒股开户选择手机办理安全吗?
- PostgreSQL source code (58) tuple splicing heap_ form_ Tuple analysis
猜你喜欢

Material design component - use bottomsheet to show extended content (I)

2021 RoboCom 世界机器人开发者大赛-高职组复赛
![[QT] test whether QT can connect to the database](/img/63/32530c15995ef23bde8cadc3adfd11.png)
[QT] test whether QT can connect to the database

2021 robocom world robot developer competition - preliminary competition of undergraduate group

S32Kxxx bootloader之UDS bootloader
![[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler](/img/35/e458fd437a0bed4bace2d6d65c9ec8.png)
[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler

Why is PHP called hypertext preprocessor
![[understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing](/img/08/9ecfd53a04e147022dde3449aec132.png)
[understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing

Notes on problems - /usr/bin/perl is needed by mysql-server-5.1.73-1 glibc23.x86_ sixty-four

多表操作-一对一,一对多与多对多
随机推荐
Anomaly-Transformer (ICLR 2022 Spotlight)复现过程及问题
TS初次使用、ts类型
力扣今日题-241. 为运算表达式设计优先级
ARP message header format and request flow
Iota in golang
在代码中使用SqlCommand对象
ADO.NET之sqlCommand对象
. env. XXX file, with constant, but undefined
2021 RoboCom 世界机器人开发者大赛-高职组复赛
Relatively easy to understand PID understanding
多表操作-一对一,一对多与多对多
MySQL Replication中并行复制怎么实现
The essence of software architecture
Why does blocprovider feel similar to provider?
Regular expression collection
How to solve the image pop-up problem when pycharm calls Matplotlib to draw
Similarities and differences between the defined identity execution function authid determiner and PostgreSQL in Oracle
Learn online case practice
Applet form verification encapsulation
股票开户哪个证券公司最好,有安全保障吗