当前位置:网站首页>牛客-练习赛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 master-slave synchronization
- ConcurrentSkipListMap——跳表原理
- [understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing
- [Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler
- [QT] qtcreator uninstall and installation (abnormal state)
- 2021 robocom world robot developer competition - preliminary competition of higher vocational group
- RPA tutorial 01: Excel automation from introduction to practice
- ARP message header format and request flow
- Is it safe to buy funds on Great Wall Securities?
- Leetcode (34) -- find the first and last positions of elements in a sorted array
猜你喜欢

写给当前及未来博士研究生一些建议整理分享

2021 RoboCom 世界机器人开发者大赛-本科组初赛

ARP message header format and request flow

Is there a piece of code that makes you convinced by human wisdom
![[es practice] safe operation mode on ES](/img/3f/fa28783770098ff10bffeccd64fe51.png)
[es practice] safe operation mode on ES

Overview of edge calculation

What category does the Internet of things application technology major belong to

The best smart home open source system in 2022: introduction to Alexa, home assistant and homekit ecosystem

2021 RoboCom 世界机器人开发者大赛-高职组复赛

Multi table operation - one to one, one to many and many to many
随机推荐
哈工大《信息内容安全》课程知识要点和难点
cookie、session、tooken
PostgreSQL source code (57) why is the performance gap so large in hot update?
SQL optimization
边缘计算概述
Current situation and future development trend of Internet of things
Kubernetes resource object introduction and common commands (III)
Key points of security agreement
ADO. Net SqlCommand object
Pytorch learning record
Iota in golang
【.Net Core】程序相关各种全局文件
Matplotlib common charts
VIM color the catalogue
How to realize parallel replication in MySQL replication
多表操作-一对一,一对多与多对多
Material design component - use bottomsheet to show extended content (I)
Zero foundation tutorial of Internet of things development
使用 pair 做 unordered_map 的键值
2021 robocom world robot developer competition - preliminary competition of higher vocational group