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. MySQL 获取物理表的主键字段

    参考代码: /** * 获取主键字段 * @param $table * @param $database * @return mixed */ public function get_primary ...

  2. 模块pandas

    python之pandas简单介绍及使用(一) https://www.cnblogs.com/misswangxing/p/7903595.html

  3. 財務会計関連(FI&CO)

    [財務会計伝票]FB01: 登録FB02: 伝票変更FB09: 明細変更FB03: 照会FB04: 変更履歴照会FB08: 反対仕訳FB05: 消込転記FB50: G/L勘定伝票一般転記FB1S: 勘 ...

  4. 在庫購買管理(MM)

    ■購買管理■ [購買依頼]ME51N: 登録ME52N: 変更ME53N: 照会 [購買発注]ME21N: 登録ME22N: 変更ME23N: 照会 [見積依頼]ME41: 登録ME42: 変更ME4 ...

  5. 流量操控之SSH隧道与端口转发

    目  录 第1章            概述... 3 1.1.         实现命令... 3 1.2.         SSH隧道类型... 3 第2章            SSH隧道... ...

  6. android apk瘦身之 图片压缩 tinypng

    参考地址: http://blog.csdn.net/jy692405180/article/details/52409369 http://www.tuicool.com/articles/BraI ...

  7. 手把手教你如何逐步安装OpenStack

    [TechTarget中国原创] 尽管OpenStack官方提供的在线安装教程和分步向导能够为管理员提供很大帮助,但是依然存在很多不尽如人意的地方.因此在Ubuntu上安装OpenStack的过程当中 ...

  8. SQL语句中的换行符

    直接看示例(顺便注意下连接符) 示例1:Access INSERT INTO ZD_DJDCB (DJH,ZDSZ) VALUES ('150105101204JC00428', '北: 地块1' + ...

  9. 《移动App性能评测与优化》读书笔记

    第一章:内存   内存的主要组成索引: Native Heap:Native代码分配的内存,虚拟机和Android框架本身也会分配 Dalvik Heap:Java代码分配的对象 Dalvik Oth ...

  10. docker部署思路

    1.docker安装2.拉取centos镜像或者Ubuntu镜像 看你用哪个3.使用镜像,run出来一个容器A4.进入容器A,安装uwsgi,把Django部署在下面5.在启动脚本中配置开机自启动脚本 ...