题目链接:

  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. PHP学习心得1

    php是动态网站开发的优秀语言,在学习的时候万万不能冒进.在系统的学习前,我认为不应该只是追求实现某种效果,因为即使你复制他人的代码调试成功,实现了你所期望的效果,你也不了解其中的原理,这样你很难利用 ...

  2. laravel多环境配置(local,testing,production)

    根据不同的环境有不同的配置,laravel中,可以把配置写到.env文件中 在系统中,可以使用env(key, "默认值")来获取env中的配置信息 在laravel中运行时,会运 ...

  3. SPOJ IM_Intergalactic Map

    判断能否从一个点同时找出两条不相交的路径到另外两个点. 保证路径不相交,那么需要拆点.然后?好像就没什么了,直接最大流即可. 不过,,,不需要求出所有的最大流,只要跑两次EK看看能否增广两次就行了. ...

  4. 【转载】JSP 获取真实IP地址的代码

    JSP 获取真实IP地址的代码 在JSP里,获取客户端的IP地址的方法是:request.getRemoteAddr(),这种方法在大部分情况下都是有效的.   但是在通过了 Apache,Squid ...

  5. python selenium2 定位一组元素find_elements实例

    打开hao123首页,需要定位以上区域中的所有链接,他们有相同的父元素<ul class="js_bd site-bd site-hd0">,所有链接处在li>a ...

  6. IoT与区块链的机遇与挑战

    区块链, 分布式账本技术的一种形式, 自从2014年或多或少地获得了大量的关注: 区块链和物联网, 区块链和安全, 区块链和金融, 区块链和物流, 凡是你能想到的,仿佛都可以应用区块链. 在本文中, ...

  7. APK反编译之一:基础知识—APK、Dalvik字节码和smali文件

    refs: APK反编译之一:基础知识http://blog.csdn.net/lpohvbe/article/details/7981386 APK反编译之二:工具介绍http://blog.csd ...

  8. java Class.getSimpleName() 的用法

    Usage in android: private static final String TAG = DemoApplication.class.getSimpleName(); public cl ...

  9. 用ladon框架封装Python为Webservice接口以及调用接口的方法

    一.用ladon框架封装Python为Webservice接口 功能实现的同时,希望将接口开放给别人,而封装python接口的一个再简单不过的框架Ladon,而且提供不同的协议,包括SOAP和Json ...

  10. 字符串化#、拼接字符##和可变参数宏(...和_ _VA_ARGS_ _)

    宏定义的使用与注意事项 ##是一个连接符号,用于把参数连在一起 #是“字符串化”的意思.出现在宏定义中的#是把跟在后面的参数转换成一个字符串#define paster( n ) printf( &q ...