hdu 5536 Chip Factory 字典树+bitset 铜牌题
Chip Factory
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1842 Accepted Submission(s): 833




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?

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
3
1 2 3
3
100 200 300
题意:给你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 铜牌题的更多相关文章
- HDU 5536 Chip Factory 字典树+贪心
给你n个数,a1....an,求(ai+aj)^ak最大的值,i不等于j不等于k 思路:先建字典树,暴力i,j每次删除他们,然后贪心找k,再恢复i,j,每次和答案取较大的,就是答案,有关异或的貌似很多 ...
- HDU 5536 Chip Factory 字典树
Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- HDU 5536 Chip Factory 【01字典树删除】
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5536 Chip Factory Time Limit: 18000/9000 MS (Java/Ot ...
- ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...
- HDU 5536 Chip Factory (暴力+01字典树)
<题目链接> 题目大意: 给定一个数字序列,让你从中找出三个不同的数,从而求出:$\max_{i,j,k} (s_i+s_j) \oplus s_k$的值. 解题分析:先建好01字典树,然 ...
- 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] ...
- 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
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
随机推荐
- C++目录
C++ lambda表达式 C++中如何设计一个类只能在堆或者栈上创建对象,面试题 C++之STL总结精华笔记 指针强制类型转换的理解 关于指针类型和指针类型转换的理解 C++继承种类 C++ 单例模 ...
- 数据分析—win7+ipython+notebook安装
先安装python 3.x 然后 cmd 执行 pip3 ipython 然后 cmd 执行 pip3 install jupyter notebook 然后 cmd 执行 jupyter noteb ...
- 【Python基础】12_Python中的容器类型公共方法
1.Python中的内置函数 注:比较两个值,使用 <. >. == 2.切片 注:字典是一个无序集合,不能切片 3.运算符 字典中的in .not in 对字段操作时,只能判断字典的k ...
- 统计学习方法 | 感知机 | python实现
感知机是二类分类的线性分类模型,利用随机梯度下降法对基于误分类的损失函数进行极小化. 书中算法可以将所有样本和系数向量写成增广向量的形式,并将所有负样本乘以-1,统一形式,方便计算. (1)训练数据集 ...
- Go-函数高级使用-条件分支-包管理-for循环-switch语句-数组及切片-与或非逻辑符
目录 科普 python 注释 # 函数高级 if else if else 包管理 下载第三方包 比较热门的框架 for 循环 for 循环的几种写法 switch 语句 数组及数组切片 数组迭代 ...
- 牛客 26E 珂学送分2 (状压dp)
珂...珂...珂朵莉给你出了一道送分题: 给你一个长为n的序列{vi},和一个数a,你可以从里面选出最多m个数 一个合法的选择的分数定义为选中的这些数的和加上额外规则的加分: 有b个额外的规则,第i ...
- KeyValuePair<string, string>
; #region CUP Method /// <summary> /// 请求与响应的超时时间 /// </summary> static public int Timeo ...
- hdu 1572 全排列的搜索
好久没写搜索的题目了 复习一下/./ 这道题目是暴力的全排列#include<cstdio> #include<iostream> #include<cstring> ...
- 轻松入门CAS系列(1)-轻松看懂企业单点登录的解决方案
常见的企业应用情况 企业内部的信息化一般都是一个过程中的 ,起初企业为了部分管理的需要,会上线几个信息化系统:后来对这块慢慢重视,信息系统会越来越多.开始,只有一两个系统时,员工还好,靠脑袋还能记得住 ...
- Android 官方下拉刷新 SwipeRefreshLayout
0.build.gradle compile 'com.android.support:support-v4:23+' 1.布局文件 <android.support.v4.widget.Swi ...