CF-B. Find The Array(构造题笔记)

鼠人今天写了每日一题,有个数学题蛮有意思的,我们来看看吧(顺便水一篇博客)


一、题目

CF-1463
B. Find The Array
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given an array [a1,a2,…,an] such that 1≤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≤bi≤109 for each i from 1 to n;
for every pair of adjacent integers from the array (bi,bi+1), either bi divides bi+1, or bi+1 divides bi (or both);
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≤t≤1000) — the number of test cases.

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

The second line contains n integers a1,a2,…,an (1≤ai≤109).

Output
For each test case, print the beautiful array b1,b2,…,bn (1≤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


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

output

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

不想读题看这里

知道你们不想看英文(我也不喜欢),我把题干大致解说一下。
现在给你一个数组a,里面有n个元素,元素之和是S,请你构造一个数组长度同为n的b数组,满足以下条件:
1.b数组内任意一个元素满足可以被数组两边的元素整除,或者整除数组两边的元素
2.从1遍历到n,满足|a[i]-b[i]|<=S/2(也就是b数组内的元素大概要在a附近,或者说,方差要小)

二、想法

我们看条件一,要满足“b数组内任意一个元素满足可以被数组两边的元素整除”这个条件,我们很容易想到1是万能的,所以我们只需要把a数组某些元素改成1就可以了
条件二要满足a,b方差够小,那其实我们只用把a数组内奇数位,偶数位分别相加对比,如果偶数位和大,就把奇数位改成1,如果奇数大则相反

来实现吧!

三、AC代码

#include
要解决 nfs - utils 和 libnsl2 安装时 libtirpc 依赖问及 libtirpc 版本冲突问,可以参考以下步骤: ### 1. 确认系统环境和软件版本 确保当前系统环境,例如引用中提到的 OS 版本为 centos - release - 7 - 8.2003.0.el7.centos.x86_64,nfs - utils 版本为 1.3.0 - 0.68.el7.x86_64 等信息,可通过以下命令查看: ```bash cat /etc/redhat-release rpm -qa | grep nfs-utils rpm -qa | grep libnsl2 rpm -qa | grep libtirpc ``` ### 2. 尝试使用 --skip-broken 选项 参考 docker 安装错误的解决思路,先按提示尝试添加 `--skip-broken` 选项来解决依赖问。例如在使用 `yum` 安装时: ```bash yum install nfs-utils libnsl2 --skip-broken ``` ### 3. 手动安装依赖库 如果 `--skip-broken` 选项不能解决问,需要手动安装合适版本的 libtirpc 库。 - 首先查找合适版本的 libtirpc 库,可以从官方软件源或镜像站下载。 - 下载完成后,使用以下命令进行安装: ```bash rpm -ivh libtirpc-<version>.rpm ``` 其中 `<version>` 是合适的 libtirpc 版本号。 ### 4. 检查和清理冲突的 libtirpc 版本 如果存在 libtirpc 版本冲突,需要卸载冲突的版本。可以使用以下命令查找并卸载: ```bash rpm -qa | grep libtirpc rpm -e libtirpc-<conflicting_version>.rpm ``` 其中 `<conflicting_version>` 是冲突的 libtirpc 版本号。 ### 5. 重新安装 nfs-utils 和 libnsl2 在解决了 libtirpc 依赖和版本冲突问后,重新安装 nfs - utils 和 libnsl2: ```bash yum install nfs-utils libnsl2 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值