#include <iostream>
#include <cstdio>
#include<algorithm>
using namespace std;
const int N = 1005;
int a[N];
int n,m;
struct Node{
int val;
Node* next[2];
Node(){
val = 0;
next[0] = next[1] = NULL;
}
void add(int number){
Node* tmp = this;
for (int i = 31; i >=0; i--){
int op = (number & (1 << i)) > 0 ? 1:0;
if (tmp->next[op] == NULL){
tmp->next[op] = new Node();
}
tmp = tmp->next[op];
tmp->val++;
}
}
void del(int number){
Node* tmp = this;
for (int i = 31; i >=0; i--){
int op = (number & (1 << i)) > 0 ? 1:0;
tmp = tmp->next[op];
tmp->val--;
}
}
int query(int value){
int ans = 0;
Node* tmp = this;
for (int i = 31; i>=0; i--){
int op = (value & (1 << i)) > 0 ? 1 : 0;
op = op ^ 1;
//为什么这里面不用担心NULL,首先肯定是有一个数在tree中
//那么tree 中肯定存在一条从头到尾的路径.
if (tmp->next[op] && tmp->next[op]->val){
ans += (1 << i);
tmp = tmp->next[op];
}else{
tmp = tmp->next[op^1];
}
}
return ans;
}
};
void del(Node* node){
if (node == NULL)
return;
if (node->next[0]){
del(node->next[0]);
}
if (node->next[1]){
del(node->next[1]);
}
delete(node);
}
int main()
{
int t = 0;
scanf("%d", &t);
Node *node = NULL;
while (t--){
scanf("%d", &n);
for (int i = 0; i < n; i++){
scanf("%d", &a[i]);
}
del(node);
node = new Node();
for (int i = 0; i < n; i++){
node->add(a[i]);
}
int ans = 0;
for (int i = 0; i < n; i++){
for (int j = i + 1; j < n; j++){
node->del(a[i]);
node->del(a[j]);
ans = max(ans, node->query(a[i] + a[j]));
node->add(a[i]);
node->add(a[j]);
}
}
printf("%d\n", ans);
}
return 0;
}
/*
2
3
1 2 3
3
100 200 300
6
400
*/
相关推荐
StarRocks FE启动异常
服务器断电,StarRocks FE 启动失败。
HDU 5536 Chip Factory (暴力 或者 01Trie)
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 236 Accepted Submission(s): 129 Problem Description John is a manager of...
基于Lora的一主多从监测与控制系统
题目:基于Lora的远程农业监测与控制系统 目的:通过Lora子节点采集好各种传感器的信息,发送给汇聚节点,汇聚节点将数据通过ESP8266上传至云端,使用了微信小程序进行监测与控制
Chip Factory(HDU-5536)
Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every processor has a serial number. More specifically,...
多目标跟踪(MOT)中的卡尔曼滤波(Kalman filter)和匈牙利(Hungarian)算法详解
多目标跟踪(MOT)中的卡尔曼滤波(Kalman filter)和匈牙利(Hungarian)算法详解 1. 概览 在开始具体讨论卡尔曼滤波和匈牙利算法之前,首先我们来看一下基于检测的目标跟踪算法的大致流程。 2. 卡尔曼滤波(Kalman filter) 目标跟踪中使用的就是最基础的 Kalman filter 算法。这里也仅仅讨论最基础的 Kalman filter 算法。 卡尔曼滤波算法的过程很简单,如下图所示。最核心的两个步骤就是预测和更新(下图的 correct)。 在目标跟踪任务中,目标的
Vue3项目实战:用vue-print-nb搞定多页表格打印(附样式不丢失解决方案)
本文详细介绍了在Vue3项目中,如何利用vue-print-nb插件解决Element Plus多页表格打印的样式丢失与分页错乱等核心难题。通过分离打印视图、编写专用CSS控制分页行为、以及深入理解浏览器打印原理,提供了一套从基础配置到高级技巧的完整企业级打印解决方案,确保打印输出专业可靠。
HDU-5536 Chip Factory,又见字典树,好题+1!
Chip Factory 题意:一个n个数的数列,求三个数其中两个数的和与另外一个数的异或值最大,输出这个最大值。 思路:和前面那个百度之星资格赛HDU4825的类似,多了两个过程,一个是枚举和,另一个是删除过程,第一次写删除操作,还一遍A了,小激动。 会不会是后台水,东北师范官方没有给出标准测试数据,也就是说这数据是hdu YY的,我猜是这样,碰到过类似的情况,错误的代...
大数据分析利器:Tableau实战教程从入门到精通
你有3家分店,每月收集1000条销售数据(日期、分店、口味、销售额、订单数);想用Excel分析“哪家分店最赚钱”,但要做透视表→改格式→画柱状图,耗时30分钟,还经常因为公式错误返工;想看看“草莓味奶茶的月度销量趋势”,得手动筛选数据、调整折线图轴范围,稍不注意就漏看关键节点;想把分析结果分享给合伙人,Excel表格太抽象,对方盯着数字问“你到底想告诉我什么?
HDU - 5536 Chip Factory(字典树)
Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every processor has a serial number. More specifically, the factory produces n chips today, the i-th chip produce
为什么我的OpenClaw安装后无法启动?Gateway服务故障排查全攻略
OpenClaw是一款功能强大的自动化工具,但其安装和运行依赖于多个服务组件,其中Gateway服务是核心组件之一。如果Gateway服务无法启动,整个OpenClaw系统将无法正常运行。本文将详细介绍OpenClaw安装后无法启动的常见原因及故障排查方法,帮助你快速定位并解决问题。
UE5 GAS 学习笔记 1.2游戏标签
这一节对GameplayTag游戏标签进行详细的讲解。
HDU - 5536 Chip Factory (01字典树)
John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every processor has a serial number. More specifically, the factory produces ...
【QT开发教程】使用Qt进行NFC编程
近场通信(NFC,Near Field Communication)技术广泛应用于现代设备中,例如智能手机、支付终端和门禁系统。Qt提供了一套完整的NFC模块,使开发者可以轻松地在应用程序中实现NFC功能。本文将介绍如何在Qt中进行NFC编程,包括基本概念、使用方法以及一些实际的示例。
hdu 5536 Chip Factory(水 | 字典树)
题目链接:hdu 5536 Chip Factory解题思路这题时限太松,纯暴力都可以,正解应该是字典树。代码#include <cstdio> #include <cstring> #include <algorithm>using namespace std; const int maxn = 55; const int dir[][2] = {{0, 1}, {0, -1}, {1, 0},
WINCC7.3破解文件
WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!
文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况
主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。
字典树-HDU 5536-Chip Factory
字典树-HDU 5536-Chip Factory 题目链接:Chip Factory 题目基础: 字典树待更 思路: 题目大意: 给n个数,任选三个不同索引位置的数,使得 (Si+Sj)^Sk 有最大值 题解: 留坑,我是用暴力悄咪咪过的 代码: #include<iostream> #include<cstdio> ...
Devexpress16.2.6破解工具
Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具
HDU 5536 Chip Factory (字典树)
题意: 给出1000个数 任取三个数 求max(ai+aj) xor ak 思路: 先计算出1e6个 ai + aj 将这1e3个数转化为2进制建树。由于数值小于1e9,树深小于32。 将1e6个 ai + aj 也转化为二进制,与trie树做抑或匹配。 每次匹配时先删除ai + aj 所在的链,再做匹配,匹配结束后再把链重新加入。 复杂度 1e6*32*5 常数小的话3s
迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)
迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)
hdu5536Chip Factory
算机学院大学生程序设计竞赛(新生为主) Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 640 Accepted Submission(s): 320 Pro
【HDU 5536】Chip Factory
1.题目链接。给定一个数组,找出来不相同的三个数使得(s[i]+s[j])^s[k]最大,并且输出这个最大值。 2.N^2枚举两个数,然后对这两个数先把他从字典树上删除,删完之后再查询和的最值,复杂度O(32*N^2). #include<bits/stdc++.h> #define LL long long using namespace std; const int maxn...
HDU5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others)Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 6984Accepted Submission(s): 3129 Problem Description John is a manag...
HDU-5536 Chip Factory
地址:http://acm.hdu.edu.cn/showproblem.php?pid=5536 思路:题目限时9s,且题目输入数据的范围也提示的很明显,就是枚举 x=a[i]+a[j],建立a[]的01字典树,再去找x的最大异或和,对于i!=j!=z,因此还要排除掉 a[i],a[j]的影响,对于树的搜索中可判断a[i],a[j]是否还在当前路径上,在就需要sum[u]>在的个数s...
Chip Factory(HDU 5536)
Chip Factory Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every processor has a serial number. More sp...
HDU 5536 Chip Factory【暴力大法好】
题目: John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every processor has a serial number. More specifically, the factory pro...
Chip Factory HDU - 5536
Chip Factory HDU - 5536 题意: 给你n个数,让你从中选出i,j,k三个下标,求最大的 (a[i]+a[j])^ a[k] 题解: 这种查找最大异或一般有两个方向,一个是有公式推导规律可循,另一个可以联合01字典树。 如何用01字典树做呢? 我们先将所有所有数插入到字典树中,然后暴力枚举i和j,求出a[i]+a[j]的和sum,现在我们要求a[k],让sum和a[k]的值最大,我们可以将sum取反,然后在字典树上找最接近sum的值,那就是符合的k,当然在查找前要先删除i和j,因为i,j
hdu5536 Chip Factory(Tire)
hdu5536题目给你一个数组,求三个元素,使得两个的和异或第三个的值最大,三个数没有先后规定但序号要不同。思路首先构建一棵2进制的Tire树,枚举i,j把他们从Tire中删去,在Tire树中从高位到低位贪心结果,最后再把i,j插回去。代码#include<cstdio> #include<cstring> #include<iostream>using namespace std;struct n
HDU5536 chip factory 【01字典树】
HDU5536 第一道字典树。2015 长春站ACM-ICPC的一道题 据说现场赛O(n^3)可以过 看了网上大牛代码以后顿悟了自己敲的。。。感觉好腻害。花了两小时弄懂代码。。第一次敲这么复杂的树 留个纪念 #include #include #include #include #include int a[1010]; using namespace std; int root ; int
1112



被折叠的 条评论
为什么被折叠?



