A题目过简单,略
B.构造+二进制
点击查看代码
#include <bits/stdc++.h>
#define LL long long
LL x, ans[40];
bool yes[40];
int main() {
std::ios::sync_with_stdio(0), std::cin.tie(0);
int T; std::cin >> T;
while (T --) {
std::cin >> x;
for (LL i = 0; i <= 31; ++ i) {
yes[i] = 0;
if (x >> i & 1) yes[i] = 1;
}
for (LL i = 0; i <= 31; ++ i) ans[i] = 0;
for (LL i = 0; i <= 31; ++ i) {
if (yes[i] == 1) {
int len = 0;
while (i <= 31 && yes[i] == 1) ++ i, ++ len;
ans[i - len] = -1, ans[i] = 1;
}
}
for (LL i = 0; i < 31; ++ i) {
if (ans[i] == -1 && ans[i + 1] == 1) {
ans[i + 1] = 0, ans[i] = 1;
}
if (ans[i] == 1 && ans[i + 1] == -1) {
ans[i + 1] = 0, ans[i] = -1;
}
}
std::cout << 32 << "\n";
for (int i = 0; i <= 31; ++ i) std::cout << ans[i] << " ";
std::cout << "\n";
}
return 0;
}