#include<algorithm> #include<iostream> #include<queue> #include<vector> usingnamespace std; constint N = 1e5 + 5; #define ll long long
voidsolve(){ int n; cin >> n; vector<int> arr(n), b; bool flag = false; for (int i = 0; i < n; i++) { cin >> arr[i]; } if (n == 1) { //特判 cout << "1" << endl; cout << arr[0] << endl; return; }
//有元素不为0 while (*max_element(arr.begin(), arr.end()) > 0) { if (b.size() >= 40) { cout << "-1" << endl; return; }
int max_elem = *max_element(arr.begin(), arr.end()); int min_elem = *min_element(arr.begin(), arr.end()); int x = (max_elem + min_elem) / 2; b.push_back(x);
for (int i = 0; i < n; i++) { arr[i] = abs(arr[i] - x); } } cout << b.size() << endl; for (constauto &item : b) { cout << item << " "; } cout << endl; }
intmain(){ int t; cin >> t; while (t--) { solve(); } return0; }
D
题意:你被给定了一个有 n 个顶点的无向图,顶点编号从 1 到 n。当且仅当 是一个素数时,顶点 u 和 v之间存在一条边,其中 ⊕表示按位异或运算。