HDU3711 Binary Number


最近杭電は10時に閉店しました!タイトルリンクがなくなりました.
長い間ブログを更新していません!最近しばらくの間、最近やったテーマを次々と分かち合うのも、自分を励ますためです.
Description
For 2 non-negative integers x and y, f(x, y) is defined as the number of different bits in the binary format of x and y. For example, f(2, 3)=1,f(0, 3)=2, f(5, 10)=4. Now given 2 sets of non-negative integers A and B, for each integer b in B, you should find an integer a in A such that f(a, b) is minimized. If there are more than one such integer in set A, choose the smallest one.
Input
The first line of the input is an integer T (0 < T ≤ 100), indicating the number of test cases. The first line of each test case contains 2 positive integers m and n (0 < m, n ≤ 100), indicating the numbers of integers of the 2 sets A and B, respectively. Then follow (m + n) lines, each of which contains a non-negative integers no larger than 1000000. The first m lines are the integers in set A and the other n lines are the integers in set B.
Output
For each test case you should output n lines, each of which contains the result for each query in a single line.
Sample Input
2
2 5
1
2
1
2
3
4
5
5 2
1000000
9999
1423
3421
0
13245
353

Sample Output
1
2
1
1
1
9999
0

テーマ:
私达に2つの集合AとBをあげて私达にAの中のすべての要素でBの中のすべての要素にマッチさせて、その中の要素のバイナリの异なる数の個数の最も小さいあれを得ます!
栗を挙げるとわかります.例えば、第1グループのデータ集合Aが(1,2)、Bが(1,2,3,4,5)です.
要素をバイナリに変換してみます.
1   -> 0001
2   -> 0010
3   -> 0011
4   -> 0100
5   -> 0101
では、(Ai,B 1)(i=0,1....A集合配列の下を表す)における(1,1)バイナリビットの異なる個数は0である.(2,1)におけるバイナリビットの異なる個数は1である.では、個数が最も小さいのはA 1に一致するときなので、最初のサンプルの出力結果は1:
#include
#include
#include
using namespace std;
//const int mINF=0XFFFFFFFF;
int a[1005],b[1005];
int fc(int x,int y)
{
	int count=0;
	while(1)
	{
		if((x&1)!=(y&1))count++;
		x=x>>1;
		y=y>>1;
		if(x==0&&y==0)return count;
	}
}
long long fmint,post;
int main()
{
//	cout<>T;
	while(T--)
	{
		int n,m;
		cin>>m>>n;
		for(int i=0;i>a[i];
		for(int i=0;i>b[i];
		sort(a,a+m);
		for(int i=0;it)fmint=t,post=j;
			}
			cout<