Chip Factory(HDU5536 + 暴力 || 01字典树)
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5536
题目:

题意:
对于给定的n个数,求出三个下标不同的数使得(si+sj)^sk最大。
思路:
由于时间给了9s,所以可以暴力过。不过还可以用01字典树艹过去,不过注意字典树里面存si查询(sj+sk),不要存(si+sj)查询sk,不然会T。
暴力代码实现如下:
#include <set>
#include <map>
#include <deque>
#include <ctime>
#include <stack>
#include <cmath>
#include <queue>
#include <string>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson rt<<1
#define rson rt<<1|1
#define name2str(name)(#name)
#define bug printf("**********\n");
#define IO ios::sync_with_stdio(false);
#define debug(x) cout<<#x<<"=["<<x<<"]"<<endl;
#define FIN freopen("/home/dillonh/CLionProjects/in.txt","r",stdin); const double eps = 1e-;
const int mod = 1e9 + ;
const int maxn = + ;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int t, n;
int s[]; int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
LL ans = -;
for(int i = ; i <= n; i++) {
scanf("%d", &s[i]);
}
for(int i = ; i <= n; i++) {
for(int j = ; j < i; j++) {
for(int k = ; k < j; k++) {
ans = max(ans, (LL)(s[i] + s[j]) ^ s[k]);
ans = max(ans, (LL)(s[i] + s[k]) ^ s[j]);
ans = max(ans, (LL)(s[j] + s[k]) ^ s[i]);
}
}
}
printf("%lld\n", ans);
}
return ;
}
01字典树:
#include <set>
#include <map>
#include <deque>
#include <ctime>
#include <stack>
#include <cmath>
#include <queue>
#include <string>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson rt<<1
#define rson rt<<1|1
#define name2str(name)(#name)
#define bug printf("**********\n");
#define IO ios::sync_with_stdio(false);
#define debug(x) cout<<#x<<"=["<<x<<"]"<<endl;
#define FIN freopen("/home/dillonh/CLionProjects/in.txt","r",stdin); const double eps = 1e-;
const int mod = 1e9 + ;
const int maxn = + ;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int t, n, le, root;
int a[], num[maxn]; struct node{
int cnt;
int nxt[]; void init(){
cnt = ;
nxt[] = nxt[] = -;
}
}T[maxn*]; void insert(int n){
int now = root;
for(int i = ; i <= ; i++) {
a[i] = n & ;
n >>= ;
}
for(int i = ; i >= ; i--){
int x = a[i];
if(T[now].nxt[x] == -){
T[le].init();
T[now].nxt[x] = le++;
}
now = T[now].nxt[x];
T[now].cnt++;
}
} LL search(int n){
int now = root;
LL ans = ;
for(int i = ; i <= ; i++) {
a[i] = n & ;
n >>= ;
}
for(int i = ; i >= ; i--){
int x = a[i];
if(T[now].nxt[-x] == - || T[T[now].nxt[-x]].cnt <= ) {
now = T[now].nxt[x];
} else {
ans += 1LL << i;
now = T[now].nxt[-x];
}
}
return ans;
} void Trie_dele(int n){
int now = ;
for(int i = ; i <= ; i++) {
a[i] = n & ;
n >>= ;
}
for(int i = ;i >= ; i--){
int tmp = a[i];
now = T[now].nxt[tmp];
T[now].cnt--;
}
} int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
le = ;
T[].init();
LL ans = -;
for(int i = ; i < n; i++) {
scanf("%d", &num[i]);
insert(num[i]);
}
for(int i = ; i < n; i++) {
Trie_dele(num[i]);
for(int j = ; j < i; j++) {
if(i == j) continue;
Trie_dele(num[j]);
ans = max(ans, search(num[i] + num[j]));
insert(num[j]);
}
insert(num[i]);
}
printf("%lld\n", ans);
}
return ;
}
Chip Factory(HDU5536 + 暴力 || 01字典树)的更多相关文章
- HDU 5536 Chip Factory (暴力+01字典树)
<题目链接> 题目大意: 给定一个数字序列,让你从中找出三个不同的数,从而求出:$\max_{i,j,k} (s_i+s_j) \oplus s_k$的值. 解题分析:先建好01字典树,然 ...
- Codeforces 979 字符串强制N变换最多出现字母 DFS子树 暴力01字典树
A /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a,b) ...
- [HDU-5536] Chip Factory (01字典树)
Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips ever ...
- Chip Factory(01字典树)
Chip Factory http://acm.hdu.edu.cn/showproblem.php?pid=5536 Time Limit: 18000/9000 MS (Java/Others) ...
- Chip Factory---hdu5536(异或值最大,01字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:有一个数组a[], 包含n个数,从n个数中找到三个数使得 (a[i]+a[j])⊕a[k] ...
- CodeForeces 842d Vitya and Strange Lesson ——(带lazy标记的01字典树)
给一个序列,每次操作对这个序列中的所有数异或一个x,问每次操作完以后整个序列的mex值. 做法是去重后构建01字典树,异或x就是对root加一个x的lazy标志,每次pushDown时如果lazy的这 ...
- Xor Sum---hdu4825(01字典树模板)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4825 题意:有n个数m个查找,每个查找有一个数x, 从序列中找到一个数y,使得x异或y最大 ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- hdu5296 01字典树
根据二进制建一棵01字典树,每个节点的答案等于左节点0的个数 * 右节点1的个数 * 2,遍历整棵树就能得到答案. AC代码: #include<cstdio> using namespa ...
随机推荐
- dstat 监控时,无颜色显示
linux:Centos 6.6 dstat:0.7.0 注意,有这个提醒:Color support is disabled, python-curses is not installed good ...
- CSS 报错
- Rotate Array II
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
- docker中间件安装记录
rabbitmq docker pull rabbitmq docker run --restart=on-failure: --name rabbitmq -d -p : -p : docker.i ...
- 2018 焦作icpc现场赛总结
Day 0 没有直达焦作的飞机,所以选择了先到新郑机场,再转乘城际列车.城际列车猜是专门给学生开通的吧,每天只有来和回一共两趟(所以机票选择的余地也不多).买的时候只有无座票了,本来以为会一直站着,但 ...
- P3223 [HNOI2012]排队
题目描述 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不同的) 输入输 ...
- SpringMVC框架并发时出现id变成另外一个用户id问题
今天测试写的代码,出现了在用一个账户登录操作的时候,操作记录的是另外一个id. 经过查找网上的解决方案确认了问题:在controller里面定义了一个userid属性,每次都通过userid传输值.然 ...
- Linux使用技巧(一):vim中选中多行、复制和粘贴
一.选中多行: 使用命令vim打开文件,移动光标至所选行的开头,按v进入视图,键盘上按向下键,选中所需行即可. 二.复制与粘贴 三种方法: 1)在上文第一部分的基础上,按y,然后移动光标至所需粘贴处, ...
- Java之IO流(字节流,字符流)
IO流和Properties IO流 IO流是指计算机与外部世界或者一个程序与计算机的其余部分的之间的接口.它对于任何计算机系统都非常关键, 因而所有 I/O 的主体实际上是内置在操作系统中的.单独的 ...
- 【纪中集训2019.3.13】fft
题意: 描述 一共有\(n+m\)道题,其中\(n\)道答案是\(A\),\(m\)道答案是\(B\): 你事先知道\(n和m\),问在最优情况下的期望答错次数,对\(998244353\)取模: 范 ...