//无脑爆居然能过!!!!!

解:其实正解也是暴力,但是可以证明在n>6时答案一定为零。

第一步:对于任意两个数他们的二进制数要么有一半+的位是相同的,要么有一半+的位是不同的,于是首先使用与运算和异或运算一定能使一半以上的位数变成0。

那么设第一步得到的数字为x,接下来我们对x与下一个数c做与运算,x上已经为0的位数一定仍为0。

对于剩下x中为1的位数,如果c中也为1的个数比较多,那么我们首先取反再做运算,如果c中为0的位数比较多那么直接做与运算,如此一定可使x中为1的位数中一半以上的位数变为0

即每部都可以使1的个数减少一半以上,因此对于64位二进制数,最多只需要7步就可以让所以的位数全部变为0.

所以对于n>6直接输出0.对于n<=6,dfs求解

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string>
#define LL long long
#define ULL unsigned long long const int MAXN=;
const int MAXM=;
const int INF=;//careful because of floyed and so on
const int MOD=;
const unsigned long long UINF=; using namespace std; int n,T;
ULL a[];
ULL ans; void dfs(int t,ULL num){
if (t>n){
ans=min(ans,num);
return;
}
if (ans==) return;
if (num==){
ans=;
return;
}
dfs(t+,num&(a[t]));
dfs(t+,num&(~a[t]));
dfs(t+,num^(a[t]));
dfs(t+,num^(~a[t]));
dfs(t+,num|(a[t]));
dfs(t+,num|(~a[t]));
} int main(){
scanf("%d",&T);
for (int cas=;cas<=T;cas++){
scanf("%d",&n);
ans=UINF;
for (int i=;i<=n;i++) scanf("%llu",&a[i]);
if (n>){
ans=;
}
else{
dfs(,a[]);
dfs(,~a[]);
}
printf("Case #%d: %llu\n",cas,ans);
}
return ;
}
/*
2
3
1 2 3
2
3 6
*/

最新文章

  1. 关于URLEnCode,URLDeCode,Base64,公钥私钥
  2. hdu 1312 Red and Black
  3. C#获取HTML文件指定DIV内容
  4. 使用NPOI完成导出Excel文件
  5. CF 353C Find Maximum #205 (Div. 2)
  6. jquery取消事件冒泡和取消默认行为
  7. 573 The Snail(蜗牛)
  8. 第八十八节,html5+css3pc端固定布局,搜索区,插入大图,搜索框
  9. 准备着手学习python
  10. Oracle集合操作
  11. C#创建安装、卸载部署程序
  12. Windows使用tail命令跟踪日志
  13. PAT 1032 挖掘机技术哪家强
  14. Change tab position of PageControl to bottom
  15. 链表用途&amp;&amp;数组效率&amp;&amp;链表效率&amp;&amp;链表优缺点
  16. Codeforces Round #370 (Div. 2) D. Memory and Scores 动态规划
  17. Revit API创建标高,单位转换
  18. 典型案例收集-使用OpenVPN连通多个机房内网(iptables+静态路由)
  19. testng日志 ITestListener
  20. Mac下使用Parallels Desktop安装CentOS操作系统

热门文章

  1. 对发给Application.Handle消息的三次执行(拦截)消息的过程
  2. Linux下的命令行上网
  3. hibernate安装和配置和第一个Hibernate应用
  4. Median of Two Sorted Arrays 解答
  5. poj 2446 (二分匹配)
  6. SQL DCL数据控制语言,用来定义訪问权限和安全级别;
  7. Android 自动更新 + IIS7 添加APK mime
  8. 写一个Windows上的守护进程(1)开篇
  9. html5的本地存储localStorage和sessionStorage
  10. iframe自适应高度的多种方法方法小结(转)