[ネタバレ注意]成都赛区验题比赛小结 by watashi@ArcOfDream » C

C
C.cpp


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int a[110], bits[1 << 22];

void solve() {

	int n, m, x;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	for (int j = 0; j < m; j++) {
		scanf("%d", &x);
		int res = 100, ans;
		for (int j = 0; j < n; j++) {
			if (bits[x ^ a[j]] < res) {
				res = bits[x ^ a[j]];
				ans = a[j];
			}
		}
//printf("a ^ b = %d, bits = %d\n", x ^ ans, bits[x ^ ans]);
		printf("%d\n", ans);
	}
}

int main() {

	for (int i = 1; i < (1 << 22); i++) bits[i] = bits[i >> 1] + (i & 1);

	int test;
	scanf("%d", &test);
	for (int i = 0; i < test; i++) {
		solve();
	}
	return 0;
}
Leave a Reply