Gym - 100814I

I. Salem
time limit per test

1 second

memory limit per test

1024 megabytes

input

standard input

output

standard output

Salem is known to be one of the best competitive programmers in the region. However, he always finds a hard time understanding the concept of the hamming distance. The hamming distance of two numbers is defined as the number of different digits in their binary representations (leading zeros are used if necessary to make the binary representations have the same length). For example the hamming distance between 12 and 5 is 2 since their binary representations are 1100 and 0101 respectively and they differ in the first and fourth positions.

Recently, Salem got a problem that he needs your help to solve. He is given N integers and asked to get the maximum among the hamming distances of all possible pairs of the given integers.

Input

The first line of the input will be a single integer T representing the number of test cases. Followed by T test cases. Each test case will start with a line with single integer (2 ≤ N ≤ 100) representing the number of the integers. Each of the following N lines contains one of the integers (1 ≤ Ai ≤ 10, 000) from the list of the integers.

Output

For each test case print one line consists of one integer representing the maximum hamming distance between all possible pairs from the given integers.

Examples
input
2
2
12
5
3
1
2
3
output
2
2 参考:
http://codeforces.com/blog/entry/21567 两种方法:
1.
int humming(int x,int y)

2.
__builtin_popcount(arr[i]^arr[j]);/
#include "cstdio"
#include "iostream"
using namespace std;
int humming(int x,int y)
{
int ans=;
while()
{
if(x==&&y==)break;
if(x%!=y%)
ans++;
x/=;y/=;
}
return ans;
}
int main()
{
int a,b;
int t,n;
int x,y;
int arr[];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d",&arr[i]);
}
int dist=,max1=;
for(int i=;i<n;i++)
{
for(int j=i;j<n;j++)
{
//dist=__builtin_popcount(arr[i]^arr[j]);///求两数最大海明差距
dist=humming(arr[i],arr[j]);
max1=max1>dist?max1:dist;
}
}
printf("%d\n",max1);
}
}

codeforces gym/100814 humming distance (二进制位数比较)的更多相关文章

  1. codeforces Gym 100814 A、B、F、I

    A题 先求出来这个数是第几大  阶乘求概率p  然后计算获得胜率的概率 常规解法把所有情况考虑一遍(跳1次,2次,3次……)要用到组合数  数可能太大了会爆的行不通 我们观察发现它有递推性质,从第二大 ...

  2. Codeforces Round #554 (Div. 2) B. Neko Performs Cat Furrier Transform(思维题+log2求解二进制位数的小技巧)

    传送门 题意: 给出一个数x,有两个操作: ①:x ^= 2k-1; ②:x++; 每次操作都是从①开始,紧接着是② ①②操作循环进行,问经过多少步操作后,x可以变为2p-1的格式? 最多操作40次, ...

  3. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  4. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  5. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

  6. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  7. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  8. codeforces gym 100553I

    codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...

  9. CodeForces Gym 100213F Counterfeit Money

    CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...

随机推荐

  1. tcl之过程/函数-proc

  2. gcc常用语法

    1. gcc -E source_file.c-E,只执行到预编译.直接输出预编译结果. 2. gcc -S source_file.c -S,只执行到源代码到汇编代码的转换,输出汇编代码. 3. g ...

  3. linux epoll用法

    epoll 是 linux 特有的 I/O 复用函数.它是把用户关心的文件描述符事件放在内核的一个事件列表中,故而,无须像select和poll一样每次调用都重复传入文件描述符或事件集.但是, epo ...

  4. Gold Balanced Lineup POJ - 3274

    Description Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been abl ...

  5. 菜鸟教程perl总结

    数据类型有:  标量$, 数组@,哈希% 数组声明 :  @hits = (25, 30, 40);  或者  @sites = qw/google taobao runoob/; 数组操作 pop, ...

  6. 用Jenkins自动化搭建测试环境

    1-1 课程介绍 2-1 Jenkins安装 2-2 Jenkins插件 2-3 Jenkins基础设置 3-1 Linux系统准备 3-2 安装Java环境 3-3 安装并配置Git 3-4 安装并 ...

  7. Tornado详解

    1.Tornado路由系统 1.1 Tornado程序示例 新建一个tornadodemo.py, import tornado.ioloop import tornado.web user_info ...

  8. [译]10-Spring BeanPostProcessor

    Spring框架提供了BeanPostProcessor接口,该接口暴露了两个方法postProcessBeforeInitialization(Object bean,String beanName ...

  9. IOS与Unity交互

    学习了宣雨松的两篇Unity和IOS交互的文章,自己动手做了下,遇到了些问题,在此记录 先说IOS发送消息给Unity:(文章地址:http://www.xuanyusong.com/archives ...

  10. Unity插件

    1.2D Toolkit 如果过去你一直从事3D游戏开发,最近想转做2D游戏,最好尝试一下2D Toolkit.2D Toolkit是一款2D开发组件,它具有很强的灵活性和适应性,能够让开发者在Uni ...