首页 > 其他分享 >UESTC 491 Tricks in Bits

UESTC 491 Tricks in Bits

时间:2022-10-18 15:01:11浏览次数:82  
标签:cnt int Tricks dfs num ans Bits 491 LL

​Tricks in Bits​

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 XOR​​​, ​​bitwise OR​​​and ​​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

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;
}





标签:cnt,int,Tricks,dfs,num,ans,Bits,491,LL
From: https://blog.51cto.com/u_15834522/5766701

相关文章

  • 【HDLBits刷题日记】02 Vectors
    Vector0向量赋值。moduletop_module(inputwire[2:0]vec,outputwire[2:0]outv,outputwireo2,outputwireo1,outputwireo0);/......
  • 【HDLBits刷题日记】01 Getting Started & Basics
    挺早以前就刷了里面一些题,结果不知道为啥登录账号刷题记录又没了,强迫症又让我不想从中间开始刷。既然如此,那就从头开始刷吧。QWQStepone第一题,没啥好说的。moduletop......
  • 设置28401事件后启动数据库时报错ORA-49100
    问题描述:设置28401事件后启动数据库时报错ORA-49100,如下所示:数据库:oracle11.2.0.464位系统:centos7.964位20:36:27SQL>altersystemsetevent='28401tracenameconte......
  • HDLBits-Verilog Practice-1-Getting started -> Circuits.Combinational Logic
    注:建议使用Ctrl+F利用关键词、题号、题目名称查阅本文内容笔记内容本文范围Gettingstarted->Circuits.CombinationalLogic网页本身给出的语法点,和一些语法......
  • HDLBits-Verilog Practice-2-Circuits.Sequential Logic -> Circuits.More Circuits
    注:建议使用Ctrl+F利用关键词、题号、题目名称查阅本文内容笔记内容本文范围Circuits.SequentialLogic->Circuits.MoreCircuits网页本身给出的语法点,和一些......
  • centos7 编译cpp报错 /usr/include/c++/4.8.2/iostream:38:28: 致命错误:bits/c++confi
    解决方法:升级gcc编译器 Centos7升级gcc安装centos-release-scl安装devtoolset 注意,如果想安装7.版本的,就改成devtoolset-7-gcc,以此类推sudoyuminstallcentos-re......
  • c++ bitset用法
    一、声明:bitset<N>f;//N是二进制长度,这时每一位都是0存储数字的二进制:bitsetname(num);//定义长度为N的二进制数组,命名为name,将数字num的二进制存到其中;b......
  • 医学影像人工智能实战(四):图像预处理的tricks
    1.空洞填充参考python-opencv去除小面积区域/孔洞填充(二值图像)2.根据连通区域去除假阳性参考深度学习,分割后处理之通过连通成分分析去除假阳性区域,提高分割准确度3.......
  • 一个小tricks
    一个小tricksphp中在传参的时候php默认将键名中的.转换为_因为版本早于8有一种方法可以解决这个问题使用[php会忽略所有的.只转换[为_例子实例代码......
  • 力扣-491-递增子序列
    起因是我做笔试,要写出所有子序列并做条件判断,我以为是回溯改一改,但事实上完全不是这样的直达链接主要是1,利用二进制序列枚举快速生成所有的可能子序列,然后利用哈希算法对......