题目传送门

题意:从n个数中选出不同的三个数a b c,使得(a+b)^c 最大

分析:先将所有数字按位插入到字典树上,然后删除两个数字,贪心询问与剩下的数字最大异或值。

/************************************************
* Author :Running_Time
* Created Time :2015/11/1 14:58:49
* File Name :J.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e3 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
struct Trie {
int ch[N*30][2], sz;
int cnt[N*30];
void init(void) {
sz = 1; ch[0][0] = ch[0][1] = 0;
memset (cnt, 0, sizeof (cnt));
}
void insert(int x) {
int u = 0;
for (int c, i=30; i>=0; --i) {
c = x & (1 << i) ? 1 : 0;
if (!ch[u][c]) {
ch[sz][0] = ch[sz][1] = 0;
ch[u][c] = sz++;
}
u = ch[u][c];
cnt[u]++;
}
}
void remove(int x) {
int u = 0;
for (int c, i=30; i>=0; --i) {
c = x & (1 << i) ? 1 : 0;
u = ch[u][c];
cnt[u]--;
}
}
int query(int x) {
int u = 0;
for (int c, i=30; i>=0; --i) {
c = x & (1 << i) ? 1 : 0;
if (c == 1) {
if (ch[u][0] && cnt[ch[u][0]]) u = ch[u][0];
else u = ch[u][1], x ^= (1 << i);
}
else {
if (ch[u][1] && cnt[ch[u][1]]) u = ch[u][1], x ^= (1 << i);
else u = ch[u][0];
}
}
return x;
}
}trie;
int a[N]; int main(void) {
int T; scanf ("%d", &T);
while (T--) {
int n; scanf ("%d", &n);
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]);
}
int ans = 0;
trie.init ();
for (int i=1; i<=n; ++i) {
trie.insert (a[i]);
}
for (int i=1; i<=n; ++i) {
trie.remove (a[i]);
for (int j=i+1; j<=n; ++j) {
trie.remove (a[j]);
ans = max (ans, trie.query (a[i] + a[j]));
trie.insert (a[j]);
}
trie.insert (a[i]);
}
printf ("%d\n", ans);
} return 0;
}

  

Trie URAL 7192 Chip Factory (15长春J)的更多相关文章

  1. Trie UVALive 7192 Chip Factory (15长春J)

    题目传送门 题意:从n个数中选出不同的三个数a b c,使得(a+b)^c 最大 分析:先将所有数字按位插入到字典树上,然后删除两个数字,贪心询问与剩下的数字最大异或值. /************* ...

  2. HDU 5536/ 2015长春区域 J.Chip Factory Trie

    Chip Factory Problem Description John is a manager of a CPU chip factory, the factory produces lots ...

  3. 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  4. 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] ...

  5. hdu 5536 Chip Factory (01 Trie)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/O ...

  6. ACM Changchun 2015 J. Chip Factory

    John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage larg ...

  7. HDU 5536 Chip Factory Trie

    题意: 给出\(n(3 \leq n \leq 1000)\)个数字,求\(max(s_i+s_j) \bigoplus s_k\),而且\(i,j,k\)互不相等. 分析: 把每个数字看成一个\(0 ...

  8. hdu5269 Chip Factory

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=5536 题目: Chip Factory Time Limit: 18000/9000 MS ( ...

  9. HDU 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

随机推荐

  1. SqlHelper c#

    using System; using System.Data; using System.Xml; using System.Data.SqlClient; using System.Collect ...

  2. hue install

    http://ju.outofmemory.cn/entry/105162 Hue是一个开源的Apache Hadoop UI系统,最早是由Cloudera Desktop演化而来,由Cloudera ...

  3. memcached的key,value,过期时间的限制

    1.   key值最大长度? memcached的key的最大长度是250个字符,是memcached服务端的限制. 如果您使用的客户端支持"key的前缀"或类似特性,那么key( ...

  4. html5中常见的全局属性

    1.contentEditable属性 1.功能说明 (1)功能:允许用户编辑元素中的内容 (2)说明:是一个布尔值,false是不能编辑,true为可编辑 该元素还隐藏一个inherit状态  也是 ...

  5. Javascript的setTimeOut()和setInterval()的定时器用法

    Javascript用来处理延时和定时任务的setTimeOut和setInterval函数应用非常广泛,它们都用来处理延时和定时任务,比如打开网页一段时间后弹出一个登录框,页面每隔一段时间发送异步请 ...

  6. js高级群的一些整理6月

    https://github.com/the5fire/backbonejs-learning-note/blob/master/chapters/01-hello-backbonejs.rst Ba ...

  7. Mongodb启动命令mongod参数说明

    Mongodb启动命令mongod参数说明 mongod的主要参数有: 基本配置 ----------------------------------------------------------- ...

  8. Codeforces#262_1002

    Codeforces#262_1002 B. Little Dima and Equation time limit per test 1 second memory limit per test 2 ...

  9. 【转】4G内存下MySQL修改配置文件以优化效率(来自discuz)

    摘要:公司网站访问量越来越大,MySQL自然成为瓶颈,因此最近我一直在研究 MySQL 的优化,第一步自然想到的是 MySQL 系统参数的优化,作为一个访问量很大的网站(日20万人次以上)的数据库. ...

  10. npm start 作用

    在配置phonecat项目时需要运行npm start在本地配置一个服务器环境,npm start首先会安装一系列的必要程序,这些程序依赖package.json中的内容,package.json中的 ...