链接:
https://codeforces.com/problemset/problem/1463/B
题意:
给一个数组a,找一个好看的数组b。如果满足bi能整除bi+1或bi能被bi+1整除,且2∑i=1n|ai−bi|≤S
则称b是好看的数组。
本题要求随便输出一个满足条件的b,所以我们对于任何一个ai都取ai二进制位的最前面一位作为bi即可,如此bi就是一个以1为首项,2为公比的等比数列中的一项,故都满足条件。
代码如下:
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<string.h>
#include<random>
using namespace std;
typedef long long ll;
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
int a;
for (int i = 0; i < n; i++) {
cin >> a;
int temp = (1 << 30);
while (!(temp & a)) {
temp >>= 1;
}
cout << temp << " ";
}
cout << endl;
}
}