UESTC 491 Tricks in Bits
| Time Limit: 1000MS | Memory Limit: 65535KB | 64bit IO Format: %lld & %llu |
Description
Given
N unsigned 
64-bit
integers, you can bitwise NOT each or not. Then you need to add operations selected from bitwise XOR, bitwise 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
2
3
1 2 3
2
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的更多相关文章
- cdoj 491 Tricks in Bits
//无脑爆居然能过!!!!! 解:其实正解也是暴力,但是可以证明在n>6时答案一定为零. 第一步:对于任意两个数他们的二进制数要么有一半+的位是相同的,要么有一半+的位是不同的,于是首先使用与运 ...
- Advanced Configuration Tricks
Advanced Configuration Tricks Configuration of zend-mvc applications happens in several steps: Initi ...
- 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 ...
- bfs UESTC 381 Knight and Rook
http://acm.uestc.edu.cn/#/problem/show/381 题目大意:给你两个棋子:车.马,再给你一个n*m的网格,从s出发到t,你可以选择车或者选择马开始走,图中有一些障碍 ...
- 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 ...
- UESTC 30 &&HDU 2544最短路【Floyd求解裸题】
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- UESTC 1591 An easy problem A【线段树点更新裸题】
An easy problem A Time Limit: 2000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others ...
- UESTC 1584 Washi与Sonochi的约定【树状数组裸题+排序】
题目链接:UESTC 1584 Washi与Sonochi的约定 题意:在二维平面上,某个点的ranked被定义为x坐标不大于其x坐标,且y坐标不大于其y坐标的怪物的数量.(不含其自身),要求输出n行 ...
- UESTC 1599 wtmsb【优先队列+排序】
题目链接:UESTC 1599 wtmsb 题意:给你一组数,每一次取出两个最小的数,将这两个数的和放入这组数中,直到这组数只剩下一个,求最后剩下那个数的大小! 分析:比赛的时候首先我就看到这道题数据 ...
随机推荐
- react-native + react-native-tab-navigator 实现 TabBar
1.安装 react-native-tab-navigator yarn add react-native-tab-navigator 2.页面调用 /** * 主页面 */ import React ...
- scrollBy 相对滚动
scrollBy可以相对当前位置移动滚动条,而不是移动到绝对位置 scrollBy(0, 100); // 滚动条下移100px
- MVC的优缺点
MVC的优点 大部分用过程语言比如ASP.PHP开发出来的Web应用,初始的开发模板就是混合层的数据编程.例如,直接向数据库发送请求并用HTML显示,开发速度往往比较快,但由于数据页面的分离不是很直接 ...
- 打开eclipse中文件所在文件夹
在myeclipse中选中文件后能够打开文件所在文件夹,可是eclipse中没有直接打开文件路径的功能.须要我们自己加入. 选择:Run -> External Tools -> Exte ...
- python-扫描某一网段下的ip
#!/usr/bin/env python #-*- coding:utf-8 -*- ############################ #File Name: ipscaner.py #Au ...
- 使用webapi实现windows本地用户管理
1. 引言 最近一段时间设计和实现公司内部的基于OAuth2.0的统一身份认证中心,经梳理,公司部分自研系统可以使用OAuth2.0的方式进行身份认证,还有一部分系统无源代码,未开放接口,使用wind ...
- Xcode7中你一定要知道的炸裂调试神技【转载】
Xcode7中苹果为我们增加了两个重要的debug相关功能.了解之后觉得非常实用,介绍给大家. 1.Address Sanitizer: 妈妈再也不用担心 EXC_BAD_ACCESS EXC_BAD ...
- 小数数据精度问题Double与BigDecimal
做项目的过程中涉及到小数问题的时候,一般我都用Double类型,但是经常出现*.999999998这种数据,然后自己再手动四舍五入,简直傻的要死. 明明就是一个1.51-1.38的问题,很简单怎么会得 ...
- 如何实现uboot和linux之间的参数传递
参考http://cgxcn.blog.163.com/blog/static/132312422009101133251202/ 参考:http://blog.chinaunix.net/uid-1 ...
- 2017-5-14 湘潭市赛 Strange Optimization
Strange Optimization Accepted : Submit : Time Limit : MS Memory Limit : KB Strange Optimization Bobo ...