这道题的题意是有N个点,每个点都是由五位的十六进制数组成的,每个点之间的距离就是他们转化成二进制之后的亦或和为1的个数,问你这这些点中距离最短是多少。
虽然题目给出的点很多,但是因为他只有5位,所以一共就 5^16个。这样的话只要随机两个点看一下最小距离就好了。
AC代码:
/* ***********************************************
Author :yzkAccepted
Created Time :2016/5/15 11:22:31
TASK :ggfly.cpp
LANG :C++
************************************************ */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn=100010;
const int inf=1<<27;
int a[maxn];
int get(int val)
{
int ans=0;
while(val>0)
{
ans+=val%2;
val/=2;
}
return ans;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int casn,i,j;
cin>>casn;
for(i=1;i<=casn;i++)
{
int n;
scanf("%d",&n);
for(int j=0;j<n;j++)
scanf("%X",&a[j]);
int ans=inf;
for(int j=1;j<=1000000;j++)
{
int idx1=rand()%n;
int idx2=rand()%n;
while(idx1==idx2) idx2=rand()%n;
int val=a[idx1]^a[idx2];
ans=min(ans,__builtin_popcountl(val));
}
cout<<ans<<endl;
}
}