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

解:其实正解也是暴力,但是可以证明在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
*/

cdoj 491 Tricks in Bits的更多相关文章

  1. UESTC 491 Tricks in Bits

    Tricks in Bits Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu Submit  ...

  2. Advanced Configuration Tricks

    Advanced Configuration Tricks Configuration of zend-mvc applications happens in several steps: Initi ...

  3. Codeforces Round #491 (Div. 2)

    Codeforces Round #491 (Div. 2) https://codeforces.com/contest/991 A #include<bits/stdc++.h> us ...

  4. 【Codeforces】Round #491 (Div. 2) 总结

    [Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...

  5. HDU 5294 Tricks Device 网络流 最短路

    Tricks Device 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5294 Description Innocent Wu follows D ...

  6. CDOJ 1324 卿学姐与公主(分块)

    CDOJ 1324 卿学姐与公主(分块) 传送门: UESTC Online Judgehttp://acm.uestc.edu.cn/#/problem/show/1324 某日,百无聊赖的卿学姐打 ...

  7. CDOJ 1330 柱爷与远古法阵(高斯消元)

    CDOJ 1330 柱爷与远古法阵(高斯消元) 柱爷与远古法阵 Time Limit: 125/125MS (Java/Others)     Memory Limit: 240000/240000K ...

  8. 2015 Multi-University Training Contest 1 Tricks Device

    Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  9. [LeetCode] Number of 1 Bits 位1的个数

    Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...

随机推荐

  1. 【转】Android下编译jni库的二种方法(含示例) -- 不错

    原文网址:http://blog.sina.com.cn/s/blog_3e3fcadd01011384.html 总结如下:两种方法是:1)使用Android源码中的Make系统2)使用NDK(从N ...

  2. 一笔画问题(floyd+oular+dfs)

    一笔画问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...

  3. Android应用程序组件Content Provider简要介绍和学习计划

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6946067 在Android系统中,Conte ...

  4. 几种基于javaI/O的文件拷贝操作比较

    最近公司的项目用到文件拷贝,由于涉及到的大量大文件的拷贝工作,代码性能问题显得尤为重要,所以写了以下例子对几种文件拷贝操作做一比较: 0.文件拷贝测试方法 public static void fil ...

  5. FineUI

    window间传值: Window1.GetSaveStateReference(new string[] { TextBox1.ClientID, ak.ClientID })收 ActiveWin ...

  6. 初入 Spring.net

    IOC:Inversion Of Control 控制翻转:就是创建对象的权利由开发人员自己控制,转换到了由容器来控制 我用的是winform里的一个按键来触发的 首先要引入两个Spring.net的 ...

  7. JSON 日期格式带 T 问题

    var iso = new IsoDateTimeConverter(); iso.DateTimeFormat = "yyyy-MM-dd"; object obj = new  ...

  8. GoEasy实现web实时推送过程中的自动补发功能

    熟悉GoEasy推送的朋友都知道GoEasy推送实现web实时推送并且能够非常准确稳定地将信息推送到客户端.在后台功能中查看接收信息详情时,可有谁注意到有时候在发送记录里有一个红色的R标志?R又代表的 ...

  9. java中关于String 类型数据 的存储方式

    Constant Pool常量池的概念: 在讲到String的一些特殊情况时,总会提到String Pool或者Constant Pool,但是我想很多人都不太 明白Constant Pool到底是个 ...

  10. html基础之 input:type

    Input表示Form表单中的一种输入对象,其又随Type类型的不同而分文本输入框,密码输入框,单选/复选框,提交/重置按钮等,下面一一介绍.1,type=text输入类型是text,这是我们见的最多 ...