Bitwise operations are very powerful. If a is different from B = K, you can determine how many bits are different for K. During calculation, the field can be computed using bitwise operations, in short, bitwise operations are very powerful!
# Include <list> # include <map> # include <set> # include <queue> # include <string> # include <deque> # include <stack> # include <algorithm> # include <iostream> # include <iomanip> # include <cstdio> # include <cmath> # include <cstdlib> # include <limits. h> # include <time. h> # include <string. h> using namespace STD; # define ll long # define PI ACOs (-1.0) # define Max int_max # define min int_min # define EPS 1e-10 # define fre freopen ("a.txt ", "r", stdin) # define n 105int A [n]; int n, m; int gaogao (int K) {int I, j; int res = 0; while (k) {If (K & 1) = 1) RES ++; k >>=1;} return res ;} void Gao (int B) {int I, j; int minm = max; for (I = 0; I <n; I ++) {int K = (B ^ A [I]); int TMP = gaogao (k); If (TMP <minm) {minm = TMP; j = I ;}} printf ("% d \ n ", A [J]);} int main () {int t; scanf ("% d", & T); While (t --) {scanf ("% d", & N, & M); int I, j; for (I = 0; I <n; I ++) scanf ("% d", & A [I]); sort (A, A + n); While (M --) {int B; scanf ("% d ", & B); Gao (B) ;}} return 0 ;}