题目传送门

题目大意

给出一个长度为 \(n\) 的数组,选出一些数异或之和为 \(s1\),其余数异或之和为 \(s2\),求 \(s1+s2\) 最大时 \(s1\) 的最小值。

思路

你发现如果你设 \(s\) 为所有数的异或和,那么如果 \(s\) 某一位为 \(0\) 就可以拆成\(1\oplus 1\),不同就只能拆成 \(0\oplus 1\),所以我们应该多拆 \(0\) ,这个用线性基实现即可。

\(\texttt{Code}\)

#include <bits/stdc++.h>
using namespace std; #define Int register int
#define ll long long
#define MAXN 100005 template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');} int n,tot,b[63];
ll s,s2,a[MAXN],p[63]; void ins (ll x){
for (Int i = 1;i <= tot;++ i)
if (x & (1ll << b[i])){
if (!p[i]){p[i] = x;break;}
else x ^= p[i];
}
} signed main(){
read (n);
for (Int i = 1;i <= n;++ i) read (a[i]),s ^= a[i];
for (Int i = 62;~i;-- i) if (!(s >> i & 1)) b[++ tot] = i;
for (Int i = 62;~i;-- i) if (s >> i & 1) b[++ tot] = i;
for (Int i = 1;i <= n;++ i) ins (a[i]);
for (Int i = 1;i <= tot;++ i) if (!(s2 & (1ll << b[i]))) s2 ^= p[i];
write (s ^ s2),putchar ('\n');
return 0;
}

最新文章

  1. 苹果系统安装虚拟机 Mac如何安装虚拟机教程
  2. LLDB, iOS调试器
  3. 只需三步 快速完善网站Sitemap
  4. Request.MapPath和ServerMapPath
  5. [译] OpenStack Liberty 版本中的53个新变化
  6. Hibernate笔试总结
  7. QCustomplot使用分享(一) 能做什么事
  8. 你所不知道的ref
  9. 如何在mac上創建txt文档
  10. SQL语句 常用条件判断
  11. Swift - 判断设备方向(或监听设备方向的改变)
  12. 201521123042 Java第一周学习总结
  13. Java并发包之同步队列SynchronousQueue理解
  14. java 基础知识小结
  15. I/O多路复用之select、poll、epoll
  16. linux 常用压缩解压命令
  17. PHP 获取当前访问的完整URL
  18. 结对编程总结(胡超慧&amp;&amp;王宇)
  19. Linux中对逻辑卷的建立
  20. centos7下找不到iptables文件

热门文章

  1. js与jquery获取input输入框中的值
  2. Ansible部署及配置介绍
  3. Ajax重构
  4. 微信支付 V3 开发教程(一):初识 Senparc.Weixin.TenPayV3
  5. 20210714 noip15
  6. 硕盟SM-H2V1 HDMI转VGA 笔记本台式主机HDMI转VGA显示器转接头
  7. 在 Docker 的 CentOS7 镜像 中安装 mysql
  8. scrum项目冲刺_day09总结
  9. 【OI】WERTYU UVa 10082
  10. PHP设计模式之原型模式