题目链接:

  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字典树)的更多相关文章

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

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

  2. Codeforces 979 字符串强制N变换最多出现字母 DFS子树 暴力01字典树

    A /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a,b) ...

  3. [HDU-5536] Chip Factory (01字典树)

    Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips ever ...

  4. Chip Factory(01字典树)

    Chip Factory http://acm.hdu.edu.cn/showproblem.php?pid=5536 Time Limit: 18000/9000 MS (Java/Others)  ...

  5. Chip Factory---hdu5536(异或值最大,01字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:有一个数组a[], 包含n个数,从n个数中找到三个数使得 (a[i]+a[j])⊕a[k] ...

  6. CodeForeces 842d Vitya and Strange Lesson ——(带lazy标记的01字典树)

    给一个序列,每次操作对这个序列中的所有数异或一个x,问每次操作完以后整个序列的mex值. 做法是去重后构建01字典树,异或x就是对root加一个x的lazy标志,每次pushDown时如果lazy的这 ...

  7. Xor Sum---hdu4825(01字典树模板)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4825 题意:有n个数m个查找,每个查找有一个数x, 从序列中找到一个数y,使得x异或y最大 ...

  8. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  9. hdu5296 01字典树

    根据二进制建一棵01字典树,每个节点的答案等于左节点0的个数 * 右节点1的个数 * 2,遍历整棵树就能得到答案. AC代码: #include<cstdio> using namespa ...

随机推荐

  1. 【百度】大型网站的HTTPS实践(二)——HTTPS加密算法介绍

    大型网站的HTTPS实践(二)——HTTPS加密算法介绍 原创 网络通信/物联网 作者:AIOps智能运维 时间:2018-11-09 15:09:43  358  0 前言 在上一篇文章中,我们简要 ...

  2. 【问底】王帅:深入PHP内核(一)——弱类型变量原理探究

    来源:CSDN    http://www.csdn.net/article/2014-09-15/2821685-exploring-of-the-php 作者:王帅 摘要:PHP作为一门简单而强大 ...

  3. Memcache服务器端+Redis服务器端+PHP Memcache扩展+PHP Memcached扩展+PHP Redis扩展+MemAdmin Memcache管理工具+一些概念(更新中)

    Memcache和Redis因为操作简单,是我们常用的服务器数据缓存系统,以下文字仅作备忘记录,部份转载至网络. 一.定义 1.Memcache Memcache是一个高性能的分布式的内存对象缓存系统 ...

  4. Pscp与服务器文件传递

    1. 下载pscp.exe https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html 选择并下载pscp.exe 2. 执行cmd程 ...

  5. c++11 函数模板的默认模板参数

    c++11 函数模板的默认模板参数 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> ...

  6. 批量更新 A表的PK_ID字段

    UPDATE  ASET PK_ID=(SELECT ID FROM  B WHERE A.TAB_NAME=B.TAB_NAME AND B.IS_KEY='1' ) AB表 以TAB_NAME 做 ...

  7. 关于SDWebImage加载高清图片导致app崩溃的问题

    链接是对于SDWebImage的使用方法 http://www.cnblogs.com/JimmyBright/p/4457258.html 使用SDWebImage加载高清图片的时候,往往会报内存溢 ...

  8. java多线程 -- 创建线程的第三者方式 实现Callable接口

    Java 5.0 在 java.util.concurrent 提供了一个新的创建执行线程的方式:Callable 接口Callable 接口类似于 Runnable,两者都是为那些其实例可能被另一个 ...

  9. bzoj 1825: [JSOI2010]蔬菜庆典

    1825: [JSOI2010]蔬菜庆典 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 112  Solved: 45[Submit][Status][ ...

  10. 【bzoj3926】【Zjoi2015】诸神眷顾的幻想乡

    题解: 如果树上某个路径串的端点不是叶子,那么一定是另一个串的子串: 这样只对叶子$dfs$把$20*20$个串插入广义$SAM$就是统计本质不同的串的个数的模板了: 我不太会分析广义$SAM$的空间 ...