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
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?
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 




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 ...
随机推荐
- jupyter的控件交互
jupyter实现控件交互 jupyter notebook 是一个交互式IDE 直接上jupyter notebook界面截图
- C++11 bind和function用法
function是一个template,定义于头文件functional中.通过function<int(int, int)> 声明一个function类型,它是“接受两个int参数.返回 ...
- 【USB】struct usb_device_id 结构体详解
struct usb_device_id { /* which fields to match against? */ __u16 match_flags; //说明使用哪种匹配方式 /* Used ...
- VS2017生成一个简单的DLL文件 和 LIB文件——C语言
下面我们将用两种不同的姿势来用VS2017生成dll文件(动态库文件)和lib文件(静态库文件),这里以C语言为例,用最简单的例子,来让读者了解如何生成dll文件(动态库文件) 生成动态库文件 姿势一 ...
- 核发电站 (dp前缀优化)
大意: $n$个城市, $m$种核电站, 第$i$种假设要建在第$x$个城市, 必须满足$[x-i,x+i]$范围内无其他核电站, 求建核电站的方案数. 简单$dp$题, 设$dp[i][j]$为位置 ...
- MongoDB实战读书笔记(二):面向文档的数据
1 schema设计原则 1.1 关系型数据库的三大设计范式 第一范式(1NF)无重复的列 第二范式(2NF)属性完全依赖于主键 [ 消除部分子函数依赖 ] 第三范式(3NF)属性不依赖于其它非主属性 ...
- iOS 更改状态栏文字颜色
第一步:在info.plist中添加一个字段:view controller -base status bar 设置为NO 第二步: 在AppDelegate.m的 didFinishLaunchin ...
- LeetCode:197.上升的温度
题目链接:https://leetcode-cn.com/problems/rising-temperature/ 题目 给定一个 Weather 表,编写一个 SQL 查询,来查找与之前(昨天的)日 ...
- div 清除浮动的四种方法
概述:为了解决父级元素因为子级内部高度为0的问题 (很多情况 不方便给父级元素高,因为不知道有多少内容,让里面的盒子自动撑起高度),清除浮动本质叫闭合浮动更好一些,清除浮动就是把浮动的盒子关到里面,让 ...
- Oracle 如何查看当前的实例及切换实例
一.Oracle查看当前实例 1.打开终端,输入命令sqlpuls / as sysdba连接到数据库 2.输入命令show parameter name便可以查看当前登录数据库的参数配置,如下可以看 ...