HDU 5536 Chip Factory 【01字典树删除】
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5536
Chip Factory
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 4915 Accepted Submission(s): 2205
Problem Description
At the end of the day, he packages all the chips produced this day, and send it to wholesalers. More specially, he writes a checksum number on the package, this checksum is defined as below:
which i,j,k are three different integers between 1 and n. And ⊕ is symbol of bitwise XOR.
Can you help John calculate the checksum number of today?
Input
The first line of each test case is an integer n, indicating the number of chips produced today. The next line has n integers s1,s2,..,sn, separated with single space, indicating serial number of each chip.
1≤T≤1000
3≤n≤1000
0≤si≤109
There are at most 10 testcases with n>100
Output
题目大意:
给 N 个数,在这 N 个数里找到三个值 i, j,k 使得(i+j)⊕ k 最大,输出这个最大值。
解题思路:
每次在01字典树里删除 i 和 j 然后 (i+j)和01字典树里的匹配求最大异或值。
AC code:
#include <bits/stdc++.h>
#define ll long long int
#define INF 0x3f3f3f3f
using namespace std; const int MAXN = 1e3+;
int ch[MAXN*][];
ll value[MAXN*];
ll b[MAXN];
int num[MAXN*];
int node_cnt; void init()
{
memset(ch[], , sizeof(ch[]));
node_cnt = ;
} void Insert(ll x)
{
int cur = ;
for(int i = ; i >= ; i--){
int index = (x>>i)&;
if(!ch[cur][index]){
memset(ch[node_cnt], , sizeof(ch[node_cnt]));
ch[cur][index] = node_cnt;
value[node_cnt] = ;
num[node_cnt++] = ;
}
cur = ch[cur][index];
num[cur]++;
}
value[cur] = x;
} void update(ll x, int d)
{
int cur = ;
for(int i =; i >= ; i--){
int index = (x>>i)&;
cur = ch[cur][index];
num[cur]+=d;
}
} ll query(ll x)
{
int cur = ;
for(int i = ; i >= ; i--)
{
int index = (x>>i)&;
if(ch[cur][index^] && num[ch[cur][index^]]) cur = ch[cur][index^];
else cur = ch[cur][index];
}
return x^value[cur];
} int main()
{
int T_case, N;
scanf("%d", &T_case);
while(T_case--)
{
scanf("%d", &N);
init();
for(int i = ; i <= N; i++)
{
scanf("%lld", &b[i]);
Insert(b[i]);
}
ll ans = ;
for(int i = ; i <= N; i++){
for(int j = ; j <= N; j++){
if(i == j) continue;
update(b[i], -);
update(b[j], -);
ans = max(ans, query(b[i]+b[j]));
update(b[i], );
update(b[j], );
}
}
printf("%lld\n", ans);
}
return ;
}
HDU 5536 Chip Factory 【01字典树删除】的更多相关文章
- [HDU-5536] Chip Factory (01字典树)
Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips ever ...
- hdu 5536 Chip Factory (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/O ...
- HDU 5536 Chip Factory (暴力+01字典树)
<题目链接> 题目大意: 给定一个数字序列,让你从中找出三个不同的数,从而求出:$\max_{i,j,k} (s_i+s_j) \oplus s_k$的值. 解题分析:先建好01字典树,然 ...
- HDU 5536 Chip Factory 字典树+贪心
给你n个数,a1....an,求(ai+aj)^ak最大的值,i不等于j不等于k 思路:先建字典树,暴力i,j每次删除他们,然后贪心找k,再恢复i,j,每次和答案取较大的,就是答案,有关异或的貌似很多 ...
- hdu 4825 && acdream 1063 01字典树异或问题
题意: 给一个集合,多次询问,每次给一个k,问你集合和k异或结果最大的哪个 题解: 经典的01字典树问题,学习一哈. 把一个数字看成32位的01串,然后查找异或的时候不断的沿着^为1的路向下走即可 # ...
- HDU 5536 Chip Factory 字典树
Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...
- hdu 5536 Chip Factory 字典树+bitset 铜牌题
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- HDU 5687 Problem C 【字典树删除】
传..传送:http://acm.hdu.edu.cn/showproblem.php?pid=5687 Problem C Time Limit: 2000/1000 MS (Java/Others ...
随机推荐
- MySQL误删root用户导致无法登陆解决方法
测试环境 删除前 mysql> select user,host,password from mysql.user; +------+-----------+---------------- ...
- 基于memcache的缓存机制的6个指令
Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached ...
- linux运维基础知识
linux运维基础知识大全 一,序言 每一个微不足道的知识,也是未来的铺垫.每一份工作的薪资职位,也是曾经努力的结果. 二,服务器 1,运维人员工作职责: 1)保证数据不丢失:2)保证服务器24小时运 ...
- kafaka安装
wget https://mirrors.cnnic.cn/apache/kafka/2.0.0/kafka_2.11-2.0.0.tgz 解压 Tar -xvf kafka_2.11-2.0.0.t ...
- ClouderManger搭建大数据集群时ERROR 2003 (HY000): Can't connect to MySQL server on 'ubuntucmbigdata1' (111)的问题解决(图文详解)
问题详情 相关问题的场景,是在我下面的这篇博客里 Cloudera Manager安装之利用parcels方式(在线或离线)安装3或4节点集群(包含最新稳定版本或指定版本的安装)(添加服务)(Ubun ...
- TOJ 4394 Rebuild Road
描述 Once,in a kingdom,there are N cities.M roads have been buit such that from one city you can reach ...
- JS实现多少小时前,多少天前...
最近需要实现题目的功能,因为我的时间戳是PHP生成的,所以转换JS时间戳需要乘1000,废话不多说,看下面的代码把! 大家可以判断一下传进来的值是否为数值型,还有判断是否比当前的时间戳大!可以根据结果 ...
- 【防火墙】iptables查看、添加、删除规则
root@ROUTER:~# iptables -t -nvL 查看到当前我的端口映射下有很多规则. 1.删除端口映射规则和端口映射的链 ①先删除子链里的所有规则 iptables -t nat -F ...
- js跑步算法
<!DOCTYPE html> <html> <head> <title>JavaScript</title> <style> ...
- [转]JS组件系列——BootstrapTable 行内编辑解决方案:x-editable
本文转自:http://www.cnblogs.com/landeanfen/p/5821192.html 阅读目录 一.x-editable组件介绍 二.bootstrapTable行内编辑初始方案 ...