牛客提高D1t2 最小生成链
分析
我们发现可以把题目转化为:有一个序列a,问它的排列中相邻两个值异或的最大值的最小值
我们发现序列的构成一定是前几位全是一样的
从某一位开始左面全是0右面全是1
所以只要找到一种方案是的交界两个值异或最小即可
把是0的插入01trie,每次拿是1的查询异或最小值
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int n,m,sum[][],trie[][],cnt;
long long a[],res,ans;
inline void q(long long x){
int i,p=;
for(i=;i>=;i--){
int wh=(x&(1ll<<i))?:;
if(trie[p][wh]){
p=trie[p][wh];
}else p=trie[p][wh^],res|=(1ll<<i);
}
return;
}
inline void ins(long long x){
int i,p=;
for(i=;i>=;i--){
int wh=(x&(1ll<<i))?:;
if(!trie[p][wh])
trie[p][wh]=++cnt;
p=trie[p][wh];
}
return;
}
signed main(){
int i,j,k,pl=-;
scanf("%d",&n);
ans=(1ll<<);
for(i=;i<=n;i++){
scanf("%lld",&a[i]);
for(j=;j<;j++){
int wh=((1ll<<j)&a[i])?:;
sum[j][wh]++;
}
}
for(i=;i>=;i--){
if(sum[i][]==n||sum[i][]==n)continue;
pl=i;
break;
}
for(i=;i<=n;i++)
if(!((1ll<<pl)&a[i])){
ins(a[i]);
}
for(i=;i<=n;i++)
if((1ll<<pl)&a[i]){
res=;
q(a[i]);
//cout<<i<<' '<<res<<endl;
ans=min(ans,res);
}
if(pl==-)puts("");
else printf("%lld\n",ans);
return ;
}
牛客提高D1t2 最小生成链的更多相关文章
- 牛客提高集训营6 C 树(树链剖分)
题目链接 为了纪(zhuang)念(bi)写完这个树剖单独写一篇.感觉还好,也就6k嘛. 完整比赛题解:https://www.cnblogs.com/SovietPower/p/9826829.ht ...
- 【牛客提高训练营2B】分糖果
题目 发现自己一年之前非常垃圾 题目大意是给你一个\(n\)个点的环,给每个点一个\([1,a_i]\)的取值,并且满足环上任意相连两点权值不能相等,求方案数 考虑断环为链,发现不大会 不妨考虑所有\ ...
- 牛客训练41D最小相似度bfs
最小相似度 题目大意:对于位数相同的两个二进制串,SIM(A,B)为它们的相似度,也就是A^B中0的个数.现在给定一堆串,找出一个T使得max{SIM(S1,T),SIM(S2,T),......,S ...
- 【牛客提高训练营5B】旅游
题目 吉老师的题时过一年还是不会做 从\(1\)号点出发经过每条边至少一次并且还要回到\(1\)号点,这跟欧拉回路的条件非常像,但是欧拉回路的实际上是"经过每一条边恰好一次并且回到出发点&q ...
- 牛客提高R5 A.同余方程
题意 题目链接 Sol 设\(solve(x, y)\)表示\(i \in [0, x], j \in [0, y]\)满足题目要求的方案数 首先容斥一下,\(ans = solve(r_1, r_2 ...
- 牛客提高D6t3 分班问题
分析 就就就是推柿子 看官方题解吧/px 代码 #include<iostream> #include<cstdio> #include<cstring> #inc ...
- 牛客提高D6t2 破碎的序列
分析 我们不难发现对于偶数的情况只要相邻两个数不相等即可 而对于奇数的情况只要中间恰好隔一个数的两个数不相等即可 于是我们又dp[i][0/1]表示考虑到第i位,这一位和它后面离它最近的一个确定的数是 ...
- 牛客提高D6t1 积木大赛
分析 每次修改用二位差分记录一下 之后对于三维分别统计即可 代码 #include<iostream> #include<cstdio> #include<cstring ...
- 牛客提高D5t1 deco的abs
分析 傻子题? 对d取模后随便贪心即可 代码 #include<iostream> #include<cstdio> #include<cstring> #incl ...
随机推荐
- SSM003/构建Maven单模块项目(二)
一.Controller基础代码(mooc) 1.UserController.java /** *springmvc1-2:返回jsp页面 * 请求URL: /user/getUserById?us ...
- Linux下杀进程
$ ps -ef | grep firefox smx : ? :: /usr/lib/firefox-/firefox-bin smx : pts/ :: grep --color=auto fir ...
- python+selenium链接对象操作
对于链接对象常见的操作有:单击.获取链接文字.获取链接地址等: from selenium import webdriverfrom time import sleep driver = webdri ...
- win10系统Docker和VMware WorkStation共存,远程工具连接Docker
摘要:win10安装docker进行学习的两种途径: Docker for Windows Installer.exe(地址https://download.docker.com/win/stable ...
- (一) MySQL架构
1.MySQL架构 MySQL拥有分层的架构,上层是服务器层的服务和查询执行引擎,下层是存储引擎,真正负责数据的存储和提取. 服务层包含了连接和线程处理,以及大多数MySQL的核心服务,如对SQL的解 ...
- [AGC035F]Two Histograms
Description 你有一个 \(N\) 行.\(M\) 列的.每个格子都填写着 0 的表格.你进行了下面的操作: 对于每一行 \(i\) ,选定自然数 \(r_i\ (0 ≤ r i ≤ M ) ...
- Oracle 常用统计视图汇总
Oracle统计信息对数据库性能优化和故障排除都相当重要,目前接触到的与统计信息相关的视图大体有 4 个: 1.v$sysstat 视图 该视图用于记录系统级的统计信息,共 5 ...
- ListView鼠标拖
private Point Position = new Point(0, 0); private void treeFileView_ItemDrag(object sender, ItemDrag ...
- Dorado环境启动出错Spring加载不到资源Bean配置 at org.springframework.asm.ClassReader.<init>(Unknown Source)
ERROR: org.springframework.web.context.ContextLoader - Context initialization failed org.springframe ...
- Simple GB28181 System
I. Deployment / Architecture Block Diagram II. Resources Used 1. freeswitch —— sip server and media ...