博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5536 Chip Factory (暴力 或者 01Trie)
阅读量:4205 次
发布时间:2019-05-26

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

题目大意:求max( (a[i] + a[j]) ^ a[k] ) (i, j, k都不相同)

思路:暴力可搞

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define lowbit(x) (x&-x)//ios::sync_with_stdio(false);typedef long long ll;typedef long long LL;using namespace std;int a[1001];int main(){ ios::sync_with_stdio(false); int T; cin>>T; while(T--) { memset(a,0,sizeof(a)); int n; cin>>n; int ans = 0; for(int i=0;i
>a[i]; for(int i=0;i
大神的0/1trie

01Tire的时候要注意下标不同,但是数字可能相同
01Trie (3s +)
#include 
#include
#include
using namespace std; int const MAX = 1e5; int a[MAX]; struct Trie { int root, tot, next[MAX][2], cnt[MAX], end[MAX]; inline int Newnode() { memset(next[tot], -1, sizeof(next[tot])); cnt[tot] = 0; end[tot] = 0; return tot ++; } inline void Init() { tot = 0; root = Newnode(); } inline void Insert(int x) { int p = root; cnt[p] ++; for(int i = 31; i >= 0; i --) { int idx = ((1 << i) & x) ? 1 : 0; if(next[p][idx] == -1) next[p][idx] = Newnode(); p = next[p][idx]; cnt[p] ++; } end[p] = x; } inline void Del(int x) { int p = root; cnt[p] --; for(int i = 31; i >= 0; i --) { int idx = ((1 << i) & x) ? 1 : 0; p = next[p][idx]; cnt[p] --; } } inline int Search(int x) { int p = root; for(int i = 31; i >= 0; i --) { int idx = ((1 << i) & x) ? 1 : 0; if(idx == 0) { if(next[p][1] != -1 && cnt[next[p][1]]) p = next[p][1]; else p = next[p][0]; } else { if(next[p][0] != -1 && cnt[next[p][0]]) p = next[p][0]; else p = next[p][1]; } } return x ^ end[p]; } }tr; int main() { int T; scanf("%d", &T); while(T--) { tr.Init(); int n, ma = 0; scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%d", &a[i]); tr.Insert(a[i]); } for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { tr.Del(a[i]); tr.Del(a[j]); ma = max(ma, tr.Search(a[i] + a[j])); tr.Insert(a[i]); tr.Insert(a[j]); } } printf("%d\n", ma); } }

转载地址:http://dlali.baihongyu.com/

你可能感兴趣的文章
Putty远程服务器的SSH经验
查看>>
内核态与用户态
查看>>
使用mingw(fedora)移植virt-viewer
查看>>
趣链 BitXHub跨链平台 (4)跨链网关“初介绍”
查看>>
C++ 字符串string操作
查看>>
MySQL必知必会 -- 了解SQL和MySQL
查看>>
MySQL必知必会 -- 使用MySQL
查看>>
MySQL必知必会 -- 数据检索
查看>>
MySQL必知必会 -- 排序检索数据 ORDER BY
查看>>
MySQL必知必会 -- 数据过滤
查看>>
MYSQL必知必会 -- 用通配符进行过滤
查看>>
MYSQL必知必会 -- 用正则表达式进行搜索
查看>>
MySQL必知必会 -- 创建计算字段
查看>>
MySQL必知必会 -- 使用数据处理函数
查看>>
MySQL必知必会 -- 数据汇总
查看>>
MySQL必知必会 -- 子查询的使用
查看>>
POJ 3087 解题报告
查看>>
POJ 2536 解题报告
查看>>
POJ 1154 解题报告
查看>>
POJ 1661 解题报告
查看>>