链接: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): 6277    Accepted Submission(s): 2847

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 produced this day has a serial number si

.

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:

maxi,j,k(si+sj)⊕sk

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 input contains an integer T

indicating the total number of test cases.

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
For each test case, please output an integer indicating the checksum number in a line.
 
Sample Input
2
3
1 2 3
3
100 200 300
 
Sample Output
6
400
 

模板题

Source
 
实现代码;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1e3+;
int tot;
int ch[*M][],vis[*M];
ll val[*M],a[M]; void init(){
memset(vis,,sizeof(vis));
tot = ;
ch[][] = ch[][] = ;
} void ins(ll x){
int u = ;
for(int i = ;i >= ;i --){
int v = (x>>i)&;
if(!ch[u][v]){
ch[tot][] = ch[tot][] = ;
val[tot] = ;
vis[tot] = ;
ch[u][v] = tot++;
}
u = ch[u][v];
vis[u]++;
}
val[u] = x;
} void update(ll x,int c){
int u = ;
for(int i = ;i >= ;i --){
int v = (x>>i)&;
u = ch[u][v];
vis[u] += c;
}
} ll query(ll x){
int u = ;
for(int i = ;i >= ;i --){
int v = (x>>i)&;
if(ch[u][v^]&&vis[ch[u][v^]]) u = ch[u][v^];
else u = ch[u][v];
}
return x^val[u];
} int main()
{
ios::sync_with_stdio();
cin.tie(); cout.tie();
int t,n,m;
cin>>t;
while(t--){
cin>>n;
ll mx = ;
init();
for(int i = ;i <= n;i ++)
cin>>a[i],ins(a[i]);
for(int i = ;i <= n;i ++){
for(int j = i+;j <= n;j ++){
update(a[i],-); update(a[j],-);
mx = max(mx,query(a[i]+a[j]));
update(a[i],); update(a[j],);
}
}
cout<<mx<<endl;
}
}

hdu 5536 Chip Factory (01 Trie)的更多相关文章

  1. HDU 5536 Chip Factory 【01字典树删除】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5536 Chip Factory Time Limit: 18000/9000 MS (Java/Ot ...

  2. HDU 5536 Chip Factory 字典树+贪心

    给你n个数,a1....an,求(ai+aj)^ak最大的值,i不等于j不等于k 思路:先建字典树,暴力i,j每次删除他们,然后贪心找k,再恢复i,j,每次和答案取较大的,就是答案,有关异或的貌似很多 ...

  3. HDU 5536 Chip Factory 字典树

    Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  4. 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  5. HDU 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  6. hdu 5536 Chip Factory 字典树+bitset 铜牌题

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  7. HDU 5536 Chip Factory Trie

    题意: 给出\(n(3 \leq n \leq 1000)\)个数字,求\(max(s_i+s_j) \bigoplus s_k\),而且\(i,j,k\)互不相等. 分析: 把每个数字看成一个\(0 ...

  8. HDU 5536 Chip Factory (暴力+01字典树)

    <题目链接> 题目大意: 给定一个数字序列,让你从中找出三个不同的数,从而求出:$\max_{i,j,k} (s_i+s_j) \oplus s_k$的值. 解题分析:先建好01字典树,然 ...

  9. ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...

随机推荐

  1. Arcgis瓦片--js客户端加载

    接上篇博客,下载好arcgis格式的瓦片数据以后,需要用js客户端在前端加载出来.这里介绍两种方案: 1.使用超图iServer将瓦片发布成rest地图服务,或者arcgis地图服务,客户端直接加载 ...

  2. iOS----------The Apple Developer Program License Agreement has been updated.

    The Apple Developer Program License Agreement has been updated. In order to access certain membershi ...

  3. 章节九、3-Desired Capabilities介绍

    一.Desired Capabilities是selenium webdrive中已经写好的一个类,我们可以通过它来告诉selenium webdrive在Desired Capabilities是什 ...

  4. 【原】Java学习笔记023 - 字符串缓冲区_正则表达式

    package cn.temptation; import java.util.Arrays; public class Sample01 { public static void main(Stri ...

  5. c/c++ linux 进程间通信系列7,使用pthread mutex

    linux 进程间通信系列7,使用pthread mutex #include <stdio.h> #include <stdlib.h> #include <unist ...

  6. Windows server2008R2 企业内部搭建虚拟专用网络服务

    VPN英文全称是“Virtual Private Network”,就是“虚拟专用网络”.可以远程帮助用户.分公司.商业伙伴及供应商同公司的内部网建立可信的安全连接,用于经济有效地连接到商业伙伴和用户 ...

  7. Tree 树形结构

    一.树的基本概念 (1)树(Tree)的概念:树是一种递归定义的数据结构,是一种重要的非线性数据结构. 树可以是一棵空树,它没有任何的结点:也可以是一棵非空树,至少含有一个结点. (2)根(Root) ...

  8. Nginx负载均衡的4种方式 :轮询-Round Robin 、Ip地址-ip_hash、最少连接-least_conn、加权-weight=n

    这里对负载均衡概念和nginx负载均衡实现方式做一个总结: 先说一下负载均衡的概念: Load Balance负载均衡是用于解决一台机器(一个进程)无法解决所有请求而产生的一种算法. 我们知道单台服务 ...

  9. Linux:Day10 程序包管理

    YUM:yellow dog,Yellowdog Update Modifier yum repository:yum repo 存储了众多rpm包,以及包的相关的无数据文件(放置于特定目录下:rep ...

  10. 【jq】prop和attr的区别

    prop()函数的结果: 1.如果有相应的属性,返回指定属性值. 2.如果没有相应的属性,返回值是空字符串. attr()函数的结果: 1.如果有相应的属性,返回指定属性值. 2.如果没有相应的属性, ...