Loading

Educational Codeforces Round 100 (Rated for Div. 2)B. Find The Array(构造)

You are given an array [𝑎1,𝑎2,…,𝑎𝑛][a1,a2,…,an] such that 1≤𝑎𝑖≤1091≤ai≤109. Let 𝑆S be the sum of all elements of the array 𝑎a.

Let's call an array 𝑏b of 𝑛n integers beautiful if:

  • 1≤𝑏𝑖≤1091≤bi≤109 for each 𝑖i from 11 to 𝑛n;
  • for every pair of adjacent integers from the array (𝑏𝑖,𝑏𝑖+1)(bi,bi+1), either 𝑏𝑖bi divides 𝑏𝑖+1bi+1, or 𝑏𝑖+1bi+1 divides 𝑏𝑖bi (or both);
  • 2∑𝑖=1𝑛|𝑎𝑖−𝑏𝑖|≤𝑆2∑i=1n|ai−bi|≤S.

Your task is to find any beautiful array. It can be shown that at least one beautiful array always exists.

Input

The first line contains one integer 𝑡t (1≤𝑡≤10001≤t≤1000) — the number of test cases.

Each test case consists of two lines. The first line contains one integer 𝑛n (2≤𝑛≤502≤n≤50).

The second line contains 𝑛n integers 𝑎1,𝑎2,…,𝑎𝑛a1,a2,…,an (1≤𝑎𝑖≤1091≤ai≤109).

Output

For each test case, print the beautiful array 𝑏1,𝑏2,…,𝑏𝑛b1,b2,…,bn (1≤𝑏𝑖≤1091≤bi≤109) on a separate line. It can be shown that at least one beautiful array exists under these circumstances. If there are multiple answers, print any of them.

Example

input

Copy

4
5
1 2 3 4 5
2
4 6
2
1 1000000000
6
3 4 8 1 2 3

output

Copy

3 3 3 3 3
3 6
1 1000000000
4 4 8 1 3 3

构造题。一开始没有头绪甚至在瞎吉尔写,但是发现“二倍的差的绝对值之和小于等于S”,这里面的2很特殊。于是考虑按照奇偶构造。另一个条件是说相邻两个数满足一个数能被另一个数整除,比较特殊一点的就是1,因为1能够整除任意一个数。于是考虑如下构造:首先对于b[i]如果i是奇数就令b[i]为1,否则令b[i] = a[i]。对于这样构造出来的数列判断一下是否满足绝对值那个条件,满足的话直接输出,不满足的话就让i是偶数b[i]为1....反着构造一次。这两种情况一定有一种是满足的,因为把n个数分成两部分,一定有一部分大于等于n / 2。

#include <iostream>
using namespace std;
int n, a[55],low[55], b[55];
int main()
{freopen("data.txt", "r", stdin);
	int t;
	cin >> t;
	while(t--)
	{
		long long sum = 0;
		cin >> n;
		for(int i = 1; i <= n; i++) 
		{
			cin >> a[i];
			sum += 1ll * a[i];
		}
		long long tmp = 0;
		for(int i = 1; i <= n; i++)
		{
			if(i & 1)
			{
				b[i] = 1;
				tmp += 1ll * (a[i] - b[i]);
			}
			else b[i] = a[i];
		}
		if(tmp * 2 <= sum)
		{
			for(int i = 1; i <= n; i++) cout << b[i] << ' ';
			cout << endl;
			continue;
		}
		for(int i = 1; i <= n; i++)
		{
			if(!(i & 1))
			{
				b[i] = 1;
				tmp += 1ll * (a[i] - b[i]);
			}
			else b[i] = a[i];
		}
		for(int i = 1; i <= n; i++) cout << b[i] << ' ';
		cout << endl;
	}
	return 0;
}
posted @ 2020-12-18 08:49  脂环  阅读(253)  评论(1编辑  收藏  举报