码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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. }

  • 相关阅读:
    【PostgreSQL内核学习(十一)—— (CreatePortal)】
    Vue3学习记录——(9) isRef、isReactive、isProxy、toRaw
    web前端-javascript-Boolean类型(说明、true真和false假,用typeof检查)
    GoLang 单元测试打桩和 mock
    高云FPGA系列教程(4):片上逻辑分析仪GAO的使用
    (附源码)计算机毕业设计SSM基于的社区疫情管理系统
    数字档案一体化解决方案
    软件测试/测试开发丨探索AI与测试报告的完美结合,提升工作效率
    AI绘图Stable Diffusion中关键技术:U-Net的应用
    Sentinel 规则持久化
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126191854
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号