Chip Factory

Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1842    Accepted Submission(s): 833

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  chips today, the -th chip produced this day has a serial number .

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  are three different integers between  and . 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  indicating the total number of test cases.

The first line of each test case is an integer , indicating the number of chips produced today. The next line has  integers , separated with single space, indicating serial number of each chip.




There are at most  testcases with 

 
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

题意:给你n个整型数(n<=1e3),现在可以从其中选出s1,s2,s3三个数字,要求求出(s1+s2)^s3的最大值,至多

1e3组测试数据。

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
#define CT continue
#define SC scanf
const int N=1e3+10; int ch[40*N][3];
int a[N],sz,num[40*N],val[40*N];
bitset<32> v; void add(int k)
{
int p=0;
for(int i=30;i>=0;i--){
int id=v[i];
if(ch[p][id]==-1) ch[p][id]=++sz;
p=ch[p][id];
num[p]+=k;
}
if(k!=-1) val[p]=v.to_ullong();//返回bitset的值
} int query()
{
int p=0;
for(int i=30;i>=0;i--){
int id=v[i],ano=ch[p][!id];
if(ano!=-1&&num[ano]!=0) p=ano;
else p=ch[p][id];
}
return val[p];
} int main()
{
int cas,n;
SC("%d",&cas);
while(cas--){
MM(ch,-1);MM(num,0);sz=0;
SC("%d",&n);
for(int i=1;i<=n;i++){
SC("%d",&a[i]);
v=a[i];
add(1);
} int ans=0;
for(int i=1;i<=n;i++){
v=a[i];add(-1);
for(int j=i+1;j<=n;j++){
v=a[j];add(-1);
v=a[i]+a[j];
ans=max(ans,(a[i]+a[j])^query());
v=a[j];add(1);
}
v=a[i];add(1);
}
printf("%d\n",ans);
}
return 0;
}

 错因:刚开始想到的是枚举下s1+s2,然后,,插入s3,,,但是发现根本处理不了重合的情况,,,。。

解答:其实先依次添加元素建好字典树后,,可以n^2的枚举s1+s2,同时在字典树中抹去这两个元素,

这时再插入s3,,每次操作完成后都将s1,s2再添加进去。。

hdu 5536 Chip Factory 字典树+bitset 铜牌题的更多相关文章

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

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

  2. HDU 5536 Chip Factory 字典树

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

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

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

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

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

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

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

  6. hdu5536 Chip Factory 字典树+暴力 处理异或最大 令X=(a[i]+a[j])^a[k], i,j,k都不同。求最大的X。

    /** 题目:hdu5536 Chip Factory 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:给定n个数,令X=(a[i]+a[j] ...

  7. hdu 5536 Chip Factory (01 Trie)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/O ...

  8. HDU 5536 Chip Factory

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

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

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

随机推荐

  1. MySQL8.0哪些新特性你最期待

    1.数据字典全部采用InnoDB引擎存储,支持DDL原子性.crash safe,metadata管理更完善 2.快速在线加新列(腾讯互娱DBA团队贡献) 3.并行redo log,并提升redo l ...

  2. kubernetes kubeadm安装v1.14

    1.我们这里准备两台Centos7的主机用于安装,后续节点可以根究需要添加即可:master node01两台都得改:cat /etc/hosts192.168.71.134 master192.16 ...

  3. WIndows系统BAT文件语法和技巧 原文的地址(http://www.jb51.net/article/5828.htm)

    批处理文件是一个文本文件,这个文件的每一行都是一条DOS命令(大部分时候就好象我们在DOS提示符下执行的命令行一样),你可以使用DOS下的Edit或者Windows的记事本(notepad)等任何文本 ...

  4. BurpSuite 爆破网页后台登陆

    由于 Burp Suite是由Java语言编写而成,所以你需要首先安装JAVA的运行环境,而Java自身的跨平台性,使得软件几乎可以在任何平台上使用.Burp Suite不像其他的自动化测试工具,它需 ...

  5. javascript之取余数、去商、天花板取整、地板取整

    demo1: console.log('//求余数'); //求余数 console.log(5 % 4); console.log(6 % 4); //求商 console.log('//求商'); ...

  6. win10下搭建vue开发环境

    特别说明:下面任何命令都是在windows的命令行工具下进行输入,打开命令行工具的快捷方式如下图:     详细的安装步骤如下: 一.安装node.js 说明:安装node.js的windows版本后 ...

  7. 高性能网站建设之 MS Sql Server数据库分区

    什么是数据库分区?数据库分区是一种对表的横向分割,Sql server 2005企业版和之后的Sql server版本才提供这种技术,这种对表的横向分割不同于2000中的表分割,它对访问用户是透明的, ...

  8. vue2.0和animate.css的结合使用

    animate.css是一款前端动画库,相似的有velocity-animate. 上述是一个完整的结构.其中重要的几个点用箭头表示出来.首先在transition组件内部,需要定义两个基本的clas ...

  9. 项目构建工具之gradle

    groovy的高级特性: 可选的类型定义 def.assert.括号是可选的.字符串 .集合API.闭包: 构建脚本 项目project : group name version apply depe ...

  10. 2.3 使用 dom4j 对 xml文件进行 dom 解析

    // 使用dom4j对XML文档进行解析 CRUD public class Demo1 { //读取XML文档中第二本书的书名 <书名>javaWEB</书名> @Test ...