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 ...
随机推荐
- djang4o查询某个字段的值
# -*- coding:utf-8 -*-import os,sysBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file ...
- python从字符串内取两个符号之间的内容
#取字符串中两个符号之间的东东 def txt_wrap_by(self,start_str, end, html): start = html.find(start_str) if start &g ...
- Linux下安装配置MongoDB数据库
说明: 操作系统:CentOS 5.X 64位 IP地址:192.168.21.130 实现目的: 安装配置MongoDB数据库 具体操作: 一.关闭SElinux.配置防火墙 1.vi /etc/s ...
- JS之this那些事
一直以来,对this的讨论都是热门话题.有人说掌握了this就掌握了JavaScript的80%,说法有点夸张,但可见this的重要性.至今记录了很多关于this的零碎笔记,今天就来个小结. 本人看过 ...
- bzoj 5084: hashit
Description 你有一个字符串S,一开始为空串,要求支持两种操作 在S后面加入字母C 删除S最后一个字母 问每次操作后S有多少个两两不同的连续子串 Solution 先忽略删除操作,建出最终的 ...
- 【VMware】无法连接MKS:套接字连接尝试次数太多;正在放弃
启动我的电脑 -> 右键 -> 管理 -> 服务和应用程序 -> 服务: 将当前服务全部进行启动
- 深入理解JavaScript系列(21):S.O.L.I.D五大原则之接口隔离原则ISP
前言 本章我们要讲解的是S.O.L.I.D五大原则JavaScript语言实现的第4篇,接口隔离原则ISP(The Interface Segregation Principle). 英文原文:htt ...
- [LeetCode]22. Generate Parentheses括号生成
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- VS2012 无法启动 IIS Express Web
用记事本打开项目的.csproj文件,定位到<WebProjectProperties>,把关于IIS的配置<DevelopmentServerPort>.<Develo ...
- java常用API之DateFormat
DateFormat 类: DateFormat 类是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或时间.日期/时间格式化子类(如 SimpleDateFormat类)允许进行格 ...