Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu

Submit Status

Description

Given N unsigned 64-bit
integers, you can bitwise NOT each or not. Then you need to add operations selected from bitwise XORbitwise ORand bitwise AND, between any two successive integers and calculate the result. Your job is to
make the result as small as possible.

Input

The first line of the input is T (no
more than 1000),
which stands for the number of test cases you need to solve.

Then T blocks
follow. The first line of each block contains a single number N (1≤N≤100)
indicating the number of unsigned 64-bit
integers. Then n integers
follow in the next line.

Output

For every test case, you should output Case #k: first, where k indicates
the case number and counts from 1.
Then output the answer.

Sample Input





1 2 3 



3 6

Sample Output

Case #1: 0

Case #2: 1

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <stdio.h>
#include <math.h> using namespace std;
typedef unsigned long long int LL;
int n;
LL ans;
LL MAX;
LL a[105];
LL min(LL a,LL b){return (a<b?a:b);}
void dfs(LL num,int cnt)
{
if(ans==0)
return;
if(num==0)
{
ans=0;
return;
}
if(cnt==n+1)
{
ans=min(ans,num);
return;
}
dfs(num|(~a[cnt]),cnt+1);
dfs(num&(~a[cnt]),cnt+1);
dfs(num^(~a[cnt]),cnt+1);
dfs(num|a[cnt],cnt+1);
dfs(num&a[cnt],cnt+1);
dfs(num^a[cnt],cnt+1);
}
int main()
{
int t;
scanf("%d",&t);
int cas=0;
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%llu",&a[i]);
MAX=1;
MAX<<=63;
ans=MAX;
dfs(a[1],2);
dfs(~a[1],2);
printf("Case #%d: %llu\n",++cas,ans);
}
return 0;
}

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

  1. cdoj 491 Tricks in Bits

    //无脑爆居然能过!!!!! 解:其实正解也是暴力,但是可以证明在n>6时答案一定为零. 第一步:对于任意两个数他们的二进制数要么有一半+的位是相同的,要么有一半+的位是不同的,于是首先使用与运 ...

  2. Advanced Configuration Tricks

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

  3. 2015 UESTC Winter Training #8【The 2011 Rocky Mountain Regional Contest】

    2015 UESTC Winter Training #8 The 2011 Rocky Mountain Regional Contest Regionals 2011 >> North ...

  4. bfs UESTC 381 Knight and Rook

    http://acm.uestc.edu.cn/#/problem/show/381 题目大意:给你两个棋子:车.马,再给你一个n*m的网格,从s出发到t,你可以选择车或者选择马开始走,图中有一些障碍 ...

  5. The 15th UESTC Programming Contest Preliminary G - GC?(X,Y) cdoj1564

    地址:http://acm.uestc.edu.cn/#/problem/show/1564 题目: G - GC?(X,Y) Time Limit: 3000/1000MS (Java/Others ...

  6. UESTC 30 &&HDU 2544最短路【Floyd求解裸题】

    最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  7. UESTC 1591 An easy problem A【线段树点更新裸题】

    An easy problem A Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others ...

  8. UESTC 1584 Washi与Sonochi的约定【树状数组裸题+排序】

    题目链接:UESTC 1584 Washi与Sonochi的约定 题意:在二维平面上,某个点的ranked被定义为x坐标不大于其x坐标,且y坐标不大于其y坐标的怪物的数量.(不含其自身),要求输出n行 ...

  9. UESTC 1599 wtmsb【优先队列+排序】

    题目链接:UESTC 1599 wtmsb 题意:给你一组数,每一次取出两个最小的数,将这两个数的和放入这组数中,直到这组数只剩下一个,求最后剩下那个数的大小! 分析:比赛的时候首先我就看到这道题数据 ...

随机推荐

  1. Python——调用shell命令的三种方法

    1.用os.system(cmd)   不过取不了返回值 2.用os.popen(cmd)   要得到命令的输出内容,只需再调用下read()或readlines()等 如a=os.popen(cmd ...

  2. HDU 4632 Palindrome subsequence(区间dp)

    Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65535 K (Java/ ...

  3. C语言中函数调用过程(如何管理栈空间)

    ps:先做草稿,以后有时间再整理并贴图,:) 主要是利用栈底寄存器(ebp).栈顶寄存器(esp)跟eax寄存器(存储返回值)来实现. 假设P调用Q: P() { Q(1,2); } (跟实际情况可能 ...

  4. Connect China Azure Storage Blob By Container Token In Python SDK

    简介: 基于Python SDK,使用Container Token操作container对象.关于Token的生成可以使用Storage SDK创建,也可以使用工具快速创建供测试. 示例代码: fr ...

  5. python元组、列表的异同总结

    定义的异同: 列表(list):[] list是一种有序的集合,能够随时加入和删除当中的元素.用 [] 表示. 列表的三个特性:①创建之后也能够加减改动元素. ②元素能够是数字.字符.变量等.也能够混 ...

  6. 几段表单处理的JQuery代码(转)

    1 只接受数字输入 $("#uAge").keydown(function(event) { // 允许退格和删除键 if ( event.keyCode == 46 || eve ...

  7. codeforces Round #Pi (div.2) 567ABCD

    567A Lineland Mail题意:一些城市在一个x轴上,他们之间非常喜欢写信交流.送信的费用就是两个城市之间的距离,问每个城市写一封信给其它城市所花费的最小费用和最大的费用. 没什么好说的.直 ...

  8. 4.const

    const 放在*号的左边为指针常量,即:该指针所指向的内存空间不允许被修改.const放在*号的右边为常量指针,即:该指针的指向不允许被修改. 简单的说就是: 假设定义一个结构体 Teacher : ...

  9. Tomcat控制台输出

    在Tomcat中,默认将终端输出信息输出到: $CATALINA_HOME/logs/catalina.out  其中$CATALINA_HOME是tomcat的安装目录. tomcat启动后,该文件 ...

  10. Nginx编译安装第三方模块http_substitutions_filter_module

    Nginx编译安装第三方模块http_substitutions_filter_module 分类:服务器技术  作者:rming  时间:-- . >>ngx_http_substitu ...