看了大牛的解法 第一次知道可以产生随机数解题 在计算hamming距离时用了位运算 很简便
/*************************************************************************
> Author: xlc2845 > Mail: xlc2845@gmail.com
> Created Time: 2013年10月29日 星期二 15时35分21秒
************************************************************************/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <ctime>
#include <algorithm>
using namespace std;
int num[100001];
int hamdist(int x, int y)
{
int sum = 0, w = x ^ y;
while(w)
{
sum++;
w &= w - 1;
}
return sum;
}
int main()
{
int t;
// srand(time(NULL));
// for(int i = 0; i < 100; i++)
// {
// int x = rand()%100;
// int y = rand()%100;
// printf("%d %d\n",x,y);
// }
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%X", &num[i]);
int ans = 30;
for(int i = 0; i < 100000; i++)
{
int x = rand()%n, y = rand()%n;
while(y == x)
y = rand()%n;
ans = min(ans, hamdist(num[x], num[y]));
}
printf("%d\n",ans);
}
return 0;
}