*hdu 5536(字典树的运用)
the total number of test cases.
The first line of each test case is an integer n,
indicating the number of chips produced today. The next line has n integers s1,s2,..,sn,
separated with single space, indicating serial number of each chip.
1≤T≤1000
3≤n≤1000
0≤si≤109
There are at most 10 testcases
with n>100
3
1 2 3
3
100 200 300
400
题意:求下面这个公式的最大值:
maxi,j,k(si+sj)⊕sk
思路:如果用普通方法你要分别枚举3个数,n^3感觉会超时的。
然而完全莫有想到能用字典树,你先把所有的数保存下来,然后删去要用的i和j,再在里面找出能和a[i]+a[j]异或
出的最大值。相当于值需要枚举i和j即可。 /*好机智
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std; int a[1005]; struct node
{
int number;
int flag;
int next[2];
void ini()
{
next[0] = next[1] = 0;
flag = 0;
}
} pnode[1000005];
int root = 0;
int tot; void inser(int x)
{
int tt = root;
for(int i = 30; i >= 0; i --)
{
int t;
if(x & (1<<i))t = 1;
else t = 0;
if(!pnode[tt].next[t])
{
pnode[tt].next[t] = ++tot;
pnode[tot].number = t;
}
tt = pnode[tt].next[t];
pnode[tt].flag++;
}
} void delet(int x)
{
int tt = root;
for(int i = 30; i >= 0; i--)
{
int t;
if(x & (1<<i))t = 1;
else t = 0;
tt = pnode[tt].next[t];
pnode[tt].flag --;
}
} int query(int x)
{
int tt = root;
for(int i = 30; i >= 0; i--)
{
int t;
if(x & (1<<i)) t = 1;
else t = 0;
if(t == 1)
{
int nex = pnode[tt].next[0];
if(pnode[nex].flag > 0 && nex) tt = pnode[tt].next[0];
else
{
tt = pnode[tt].next[1];
x ^= (1<<i);
}
}
else
{
int nex = pnode[tt].next[1];
if(pnode[nex].flag > 0 && nex)
{
tt = pnode[tt].next[1];
x ^= (1<<i);
}
else tt = pnode[tt].next[0];
}
}
return x;
} int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
int ans = 0;
scanf("%d",&n);
tot = 0;
for(int i = 0; i < n; i++) scanf("%d",a+i);
for(int i = 0; i < n; i++) inser(a[i]); for(int i = 0; i < n; i++)
{
delet(a[i]);
for(int j = i+1; j < n; j++)
{
delet(a[j]);
ans = max(ans,query(a[i] + a[j]));
inser(a[j]);
}
inser(a[i]);
}
for(int i = 0;i < tot;i++)
{
pnode[i].ini();
}
printf("%d\n",ans);
}
return 0;
}
*hdu 5536(字典树的运用)的更多相关文章
- Chip Factory HDU - 5536 字典树(删除节点|增加节点)
题意: t组样例,对于每一组样例第一行输入一个n,下面在输入n个数 你需要从这n个数里面找出来三个数(设为x,y,z),找出来(x+y)^z(同样也可以(y+z)^1)的最大值 ("^&qu ...
- HDU 5536 字典树
题意:就是公式. 这现场赛O(n^3)能过,觉得太没天理了. 做法:字典树,枚举两个数,然后在字典树上贪心的跑. #include <bits/stdc++.h> using namesp ...
- HDU 5687 字典树插入查找删除
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5687 2016百度之星资格赛C题,直接套用字典树,顺便巩固了一下自己对字典树的理解 #include< ...
- HDU 5384 字典树、AC自动机
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5384 用字典树.AC自动机两种做法都可以做 #include<stdio.h> #includ ...
- hdu 2112(字典树+最短路)
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 2072(字典树模板,set,map均可做)
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072 lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词 ...
- hdu 1251 字典树的应用
这道题看了大神的模板,直接用字典树提交的会爆内存,用stl 里的map有简单有快 #include <iostream> #include <map> #include < ...
- hdu 2896 字典树解法
#include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> ...
- Repository HDU - 2846 字典树
题意:给出很多很多很多很多个 单词 类似搜索引擎一下 输入一个单词 判断有一个字符串包含这个单词 思路:字典树变体,把每个单词的后缀都扔字典树里面,这里要注意dd是一个单词 但是把d 和dd都放字典树 ...
- Phone List HDU - 1671 字典树
题意:给出一堆一组一组的数字 判断有没有哪一个是另外一个的前缀 思路:字典树 插入的同时进行判断 不过 当处理一组数字的时候 需要考虑的有两点1.是否包含了其他的序列2.是否被其他序列包含 刚开始 ...
随机推荐
- Flask 页面缓存逻辑,jinja2 过滤器,测试器
回调接入点-页面缓存逻辑 from flask import Flask,request,render_template from werkzeug.contrib.cache import Simp ...
- 使用Github pages+jekyll搭建自己的博客(windows版)
最近突发奇想,想试试GitHub pages来搭建博客.网上一搜一大堆,嗯...看来还是挺简单的...于是自己撸起袖子干...... 结果对于我这种GitHub注册过,git 没用过,ruby.jek ...
- LeetCode & Q53-Maximum Subarray-Easy & 动态规划思路分析
Array DP Divide and Conquer Description: Find the contiguous subarray within an array (containing at ...
- 移动端300ms与点透总结
300ms,主要发生在mobile 为啥会出现300ms延迟现象 浏览器想知道用户是否dobule tap(双击缩放) 下列情况不会出现300ms延迟 桌面浏览器 meta的viewport设置了us ...
- hadoop大数据技术架构详解
大数据的时代已经来了,信息的爆炸式增长使得越来越多的行业面临这大量数据需要存储和分析的挑战.Hadoop作为一个开源的分布式并行处理平台,以其高拓展.高效率.高可靠等优点越来越受到欢迎.这同时也带动了 ...
- Mosquito集群模式
参考链接: http://blog.csdn.net/z729685731/article/details/70142182 http://blog.csdn.net/yuhaiyang457288/ ...
- 安装 docker-compose
安装Docker-Compose之前,请先安装 python-pip,安装好pip之后,就可以安装Docker-Compose了. 一.检查是否已经安装 二.安装 docker-compose 1.安 ...
- hadoop2.6.0实践:A03 例子验证
[hadoop@LexiaofeiN1 ~]$ hdfs dfs -ls /output/grep[hadoop@LexiaofeiN1 ~]$ hdfs dfs -rm -R /output/gre ...
- MFC基础
入门博客:http://www.cnblogs.com/qinfengxiaoyue/category/451679.html 消息机制:http://www.cnblogs.com/qinfengx ...
- python2 当中 遇到 UnicodeDecodeError UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 37: ordinal not in range(128)
使用python2 总是遇到 UnicodeDecodeErrorUnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in positio ...