• B. Find The Array


    B. Find The Array

    time limit per test

    2 seconds

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    You are given an array [a1,a2,…,an][a1,a2,…,an] such that 1≤ai≤1091≤ai≤109. Let SS be the sum of all elements of the array aa.

    Let's call an array bb of nn integers beautiful if:

    • 1≤bi≤1091≤bi≤109 for each ii from 11 to nn;
    • for every pair of adjacent integers from the array (bi,bi+1)(bi,bi+1), either bibi divides bi+1bi+1, or bi+1bi+1 divides bibi (or both);
    • 2∑i=1n|ai−bi|≤S2∑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 tt (1≤t≤10001≤t≤1000) — the number of test cases.

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

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

    Output

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

    =========================================================================

    很巧妙,突破点在于 不等式左边的2,不妨让bi一定小于ai,这样的话,我们将bi构造成第一个小于ai的2的若干次幂。这样二者只差一定小于ai/2

    证明如下,如果 bi*2==ai 那么恰好是一半

    bi*2>ai 那么一定小于一半

    bi*2

    1. #include
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. using namespace std;
    8. typedef long long ll;
    9. ll er[50];
    10. void init()
    11. {
    12. er[0]=1ll;
    13. for(int i=1;i<=32;i++)
    14. {
    15. er[i]=er[i-1]*2ll;
    16. }
    17. }
    18. int main()
    19. {
    20. int t;
    21. init();
    22. cin>>t;
    23. while(t--)
    24. {
    25. int n,x;
    26. cin>>n;
    27. for(int i=1;i<=n;i++)
    28. {
    29. cin>>x;
    30. cout<max(0ll,lower_bound(er,er+33,x)-er-1)]<<" ";
    31. }
    32. cout<
    33. }
    34. return 0;
    35. }

  • 相关阅读:
    关机恶搞小程序
    人工智能在汽车业应用的五项挑战
    Linux简介
    使用OLED透明广告屏,涉及到的附加费用
    lua-快速入门学习
    Ubuntu中nano使用
    /etc/sysctl.conf的参数
    代码,敲开新世界的大门
    看界面控件DevExpress WinForms——如何自定义辅助功能属性(下)
    【lesson12】进程地址空间初识
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126191854