中南大学COJ 1216: 异或最大值(数据结构)
来源:互联网 发布:js查看某个属性值 编辑:程序博客网 时间:2024/05/17 02:21
中南大学COJ 1216: 异或最大值(数据结构)
ACM
题目地址:COJ 1216
题意:
中文题,注意是多组样例。
分析:
用01Trie做的。
代码:
/** Author: illuz <iilluzen[at]gmail.com>* File: coj1216.cpp* Create Date: 2014-07-27 14:18:44* Descripton: trie*/#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;const int N = 100000<<5;struct Trie {int a[2];int num;} f[N];int cnt, ans;// insert x into the root which id is u, the deep is numvoid insert(int x, int u, int num) {bool k;for (int i = num; i >= 0; i--) {k = (1<<i)&x;if (f[u].a[k] == -1)f[u].a[k] = ++cnt;u = f[u].a[k];}f[u].num = x;}// query xorvoid query(int x, int u, int num) {bool k;for (int i = num; i >= 0; i--) {k = (1<<i)&x;if (f[u].a[!k] != -1)u = f[u].a[!k];elseu = f[u].a[k];}ans = max(ans, f[u].num^x);}int main() {int n, t;while (~scanf("%d", &n)) {memset(f, -1, sizeof(Trie) * N);cnt = 0;ans = 0;while (n--) {scanf("%d", &t);insert(t, 0, 31);query(t, 0, 31);}printf("%d\n", ans);}return 0;}
2 0
- 中南大学COJ 1216: 异或最大值(数据结构)
- COJ 1216 异或最大值
- COJ-1216 异或最大值
- 中南大学 计算机 数据结构真题
- COJ 1216 最大异或值
- CSU 1869 中南大学网络赛C题 树上最大值
- 关于中南大学数据结构/C++课设题目的一点思考(一·简单题)
- 湖南省首届逻辑推理大赛(中南大学)
- 中南大学数学天才
- 中南大学oj1327
- 湘潭大学中南邀请赛
- CSU 1216 异或最大值
- csu-1216: 异或最大值
- CSU_1216(异或最大值)
- 中南大学oj1320(大数+卡特兰数)
- 中南大学OJ 1046 追杀
- 中南大学软件工程修习课程
- CSUOJ 1216 异或最大值 (01Trie)
- 类型转换——int转换成char(截短)
- HDOJ 题目1060Leftmost Digit(数学)
- google 访问
- 容器
- 表连接初识
- 中南大学COJ 1216: 异或最大值(数据结构)
- 进程间通信______消息队列
- VS项目配置中 C++目录--包含目录(or库目录继承值的删除问题)
- maven仓库快速镜像
- 广告植入在小时代的狂欢
- 2014/7/27------数据库的隔离性
- Square(DFS)
- 这个周末刚刚上映的《小时代3》
- next数组