显然要x的二进制下的每一位都出现偶数次,那么显然x为奇数的时候直接不行。偶数直接/2得到x/2、x/2。也就是说n至少长度为2,此时最简单的方法就是构造x/2,x/2,...其余全部用0填充。
解法:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define endl '\n'
void solve(int n,int x) {
if (x & 1) {
cout << -1 << endl;
return;
}
cout << x / 2 << " " << x / 2 << " ";
n -= 2;
while (n--) {
cout << 0 << " ";
}
cout << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t, n, x;
cin >> t;
while (t--) {
cin >> n >> x;
solve(n, x);
}
return 0;
}