BZOJ 4269 再见Xor
2016-06-05 15:30
302 查看
线性基。
求次大值就是再异或一个线性基好了。
求次大值就是再异或一个线性基好了。
#include<iostream> #include<cstdio> #include<cstring> #define maxn 100050 using namespace std; int n,a[maxn],ins[maxn]; int main() { scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]); for (int i=1;i<=n;i++) { for (int j=30;j>=0;j--) { if (a[i]&(1<<j)) { if (!ins[j]) { ins[j]=a[i]; break; } else a[i]^=ins[j]; } } } int ans1=0,ans2=0; for (int i=30;i>=0;i--) if ((ans1^ins[i])>ans1) ans1^=ins[i]; for (int i=30;i>=0;i--) if ((ans1^ins[i])<ans1) ans2=max(ans2,(ans1^ins[i])); printf("%d %d\n",ans1,ans2); return 0; }
相关文章推荐
- Ubuntu 15.04 安装JDK并配置成为默认的JDK
- Android静态安全检测 -> 文件任意读写
- OpenGL中的FBO对象(含源码)
- Linux命令中选项前的-
- 使用git来上传项目
- ACM天梯赛练习L1-007. 念数字
- 什么是计算机服务
- 欢迎使用CSDN-markdown编辑器
- HDU2002
- Publishing failed with multiple errors Could not delete *,May be locked by another process.
- 避免多重继承引起的冲突——虚基类
- jdbc优化-DButils的使用
- WinForm窗体间传值的方法
- leetcode 177. Nth Highest Salary
- 关于布局的学习
- HDU2001
- C/C++数据对齐
- mysql explain分析sql语句的执行计划
- AlertDialog对话框
- [导入]Eclipse 导入/编译 Hadoop 源码