博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU-5536 Chip Factory (字典树)
阅读量:4657 次
发布时间:2019-06-09

本文共 1295 字,大约阅读时间需要 4 分钟。

题目大意:给n个数,编号为1~n,取三个编号不同的数,使表达式(a+b)^c的值最大。

题目分析:将这n个数按二进制位建立一棵trie。枚举i、j的和,查询亦或最大值,但在查询之前要把i、j在trie中删除,查询完毕后再插入trie。

 

ps:用数组实现trie会超时,因为每次test case之前都要初始化数组,非常耗时。

 

代码如下:

# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
using namespace std;# define LL long longconst int N=1000;const int INF=1000000000;const double inf=1e20;struct Node{ int cnt; Node *son[2]; Node(){ cnt=0; son[0]=son[1]=NULL; }};Node *root;int a[N+5];int n;void update(int x){ Node *p=root; for(int i=30;i>=0;--i){ int k=(x&(1<
0?1:0; if(p->son[k]==NULL) p->son[k]=new Node(); ++(p->son[k]->cnt); p=p->son[k]; }}void erase(LL x){ Node *p=root; for(int i=30;i>=0;--i){ int k=(x&(1<
0?1:0; --(p->son[k]->cnt); p=p->son[k]; }}int query(int x){ int res=0; Node *p=root; for(int i=30;i>=0;--i){ int k=(x&(1<
0?1:0; if(p->son[k^1]!=NULL&&p->son[k^1]->cnt>0){ res|=(1<
son[k^1]; }else{ p=p->son[k]; } } return res;}void delTree(Node *p){ if(p==NULL) return ; delTree(p->son[0]); delTree(p->son[1]); delete p;}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d",&n); root=new Node(); for(int i=0;i

  

转载于:https://www.cnblogs.com/20143605--pcx/p/5475559.html

你可能感兴趣的文章
【洛谷 1168】动态中位数
查看>>
DNS安装配置
查看>>
tab 命令
查看>>
[待解决]LR9.5添加SiteScope9.5的问题
查看>>
RadioButtonList 属性设置
查看>>
Python 基础--Python介绍
查看>>
python爬虫-简单使用xpath下载图片
查看>>
python读取txt里的json文件,存到excel,例子1
查看>>
异常处理
查看>>
BaseDao
查看>>
【codevs1282】约瑟夫问题
查看>>
【codevs1081】线段树练习2
查看>>
作业13——web基础
查看>>
原生JS获取所有标签的数量并统计每个标签的数量
查看>>
slf4j简单使用
查看>>
vue2.0 keep-alive最佳实践
查看>>
Spring Boot入门
查看>>
【OpenCV学习】椭圆拟合
查看>>
探索C#之6.0语法糖剖析
查看>>
练习2.1
查看>>