【BZOJ-4269】再见Xor 高斯消元 + 线性基
2016-05-22 11:39
302 查看
4269: 再见Xor
Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 131 Solved: 81
[Submit][Status][Discuss]
Description
给定N个数,你可以在这些数中任意选一些数出来,每个数可以选任意多次,试求出你能选出的数的异或和的最大值和严格次大值。Input
第一行一个正整数N。接下来一行N个非负整数。
Output
一行,包含两个数,最大值和次大值。Sample Input
33 5 6
Sample Output
6 5HINT
100% : N <= 100000, 保证N个数不全是0,而且在int范围内Source
Solution
学线性基,还没完全学透,这是到纯模板题...于是...Code
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> using namespace std; #define maxn 100010 int a[maxn],n; void Gauss() { int tmp=0,i; for (int j=1<<30; j; j>>=1) { for (i=tmp+1; i<=n; i++) if (a[i]&j) break; if (i>n) continue; swap(a[++tmp],a[i]); for (i=1; i<=n; i++) if (i!=tmp && a[i]&j) a[i]^=a[tmp]; } n=tmp; } int main() { scanf("%d",&n); for (int i=1; i<=n; i++) scanf("%d",&a[i]); Gauss(); int maxx=0; for (int i=1; i<=n; i++) maxx^=a[i]; int cmaxx=maxx^a ; printf("%d %d\n",maxx,cmaxx); return 0; }
相关文章推荐
- win10 ctrl + 空格 热键取消
- linux下面根据不同的日期创建不同文件,一般用户数据库的备份的shell编程
- CSS伪类选择器 -- nth-child(an+b):
- Linux文件系统和目录的作用
- c++ 默认构造函数
- 重要学习网站记录
- HTTP返回代码 201 304 404 500等代表的含义
- iOS 开发之Target-action模式
- Tomcat init 脚本并添加服务自启动
- 342. Power of Four
- [BZOJ1006][HNOI2008]神奇的国度(弦图最小染色)
- datetimepicker 插件用法及参数说明
- cocos2d-x游戏引擎核心(3.x)----事件分发机制之事件从(android,ios,desktop)系统传到cocos2dx的过程浅析
- mongoVUE 连接MongoDB3.2.2不能正常显示collection的问题
- Objective-C ---代理和协议 (梳理整理)
- 谷歌约束控件(ConstraintLayout)扁平化布局入门
- Linux时间日期设置相关命令
- 序列模型-RNN
- 还在用ListView?!OutMan!RecyclerView!
- 二叉树相关笔试题(三)