当前位置:网站首页>牛客-练习赛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;
}
边栏推荐
- Redis RDB snapshot
- Door level modeling - after class exercises
- Applet form verification encapsulation
- notBlank 和 notEmpty
- Concurrentskiplistmap -- principle of table skipping
- Pytorch learning record
- [Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler
- Windows 7 安装MYSQL 错误:1067
- Y53. Chapter III kubernetes from introduction to mastery -- ingress (26)
- Linux foundation - centos7 offline installation of MySQL
猜你喜欢
TS初次使用、ts类型
RPA tutorial 01: Excel automation from introduction to practice
Kubernetes resource object introduction and common commands (III)
[QT] solve the problem that QT MSVC 2017 cannot compile
有没有一段代码,让你为人类的智慧所折服
Using uni simple router, dynamically pass parameters typeerror: cannot convert undefined or null to object
Pytorch learning record
ARP报文头部格式和请求流程
Postgresql源码(57)HOT更新为什么性能差距那么大?
[QT] test whether QT can connect to the database
随机推荐
notBlank 和 notEmpty
2022-07-01:某公司年会上,大家要玩一食发奖金游戏,一共有n个员工, 每个员工都有建设积分和捣乱积分, 他们需要排成一队,在队伍最前面的一定是老板
【QT】对于Qt MSVC 2017无法编译的问题解决
Li Kou today's question -241 Design priorities for operational expressions
Concurrentskiplistmap -- principle of table skipping
Redis master-slave synchronization
The essence of software architecture
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
SecurityUtils.getSubject().getPrincipal()为null的问题怎么解决
字典、哈希表、数组的概念
[QT] test whether QT can connect to the database
PostgreSQL notes (10) dynamically execute syntax parsing process
Using SqlCommand objects in code
【CMake】Qt creator 里面的 cmake 配置
Regular expression collection
2021 robocom world robot developer competition - preliminary competition of undergraduate group
Current situation and future development trend of Internet of things
How excel opens CSV files with more than one million lines
Multi table operation - one to one, one to many and many to many
RPA tutorial 01: Excel automation from introduction to practice