• D. Vus the Cossack and Numbers


    D. Vus the Cossack and Numbers

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Vus the Cossack has nn real numbers aiai. It is known that the sum of all numbers is equal to 00. He wants to choose a sequence bb the size of which is nn such that the sum of all numbers is 00 and each bibi is either ⌊ai⌋⌊ai⌋ or ⌈ai⌉⌈ai⌉. In other words, bibi equals aiai rounded up or down. It is not necessary to round to the nearest integer.

    For example, if a=[4.58413,1.22491,−2.10517,−3.70387]a=[4.58413,1.22491,−2.10517,−3.70387], then bb can be equal, for example, to [4,2,−2,−4][4,2,−2,−4].

    Note that if aiai is an integer, then there is no difference between ⌊ai⌋⌊ai⌋ and ⌈ai⌉⌈ai⌉, bibi will always be equal to aiai.

    Help Vus the Cossack find such sequence!

    Input

    The first line contains one integer nn (1≤n≤1051≤n≤105) — the number of numbers.

    Each of the next nn lines contains one real number aiai (|ai|<105|ai|<105). It is guaranteed that each aiai has exactly 55 digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to 00.

    Output

    In each of the next nn lines, print one integer bibi. For each ii, |ai−bi|<1|ai−bi|<1 must be met.

    If there are multiple answers, print any.

    Examples

    input

    Copy

    4
    4.58413
    1.22491
    -2.10517
    -3.70387
    

    output

    Copy

    4
    2
    -2
    -4
    

    input

    Copy

    5
    -6.32509
    3.30066
    -0.93878
    2.00000
    1.96321
    

    output

    Copy

    -6
    3
    -1
    2
    2
    

    Note

    The first example is explained in the legend.

    In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.

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

    贪心一下,先都向下取整,求出来和,小于零就加1,加1的情况只在a[i]不等于b[i]的时候

    1. # include
    2. # include
    3. # include
    4. using namespace std;
    5. int main()
    6. {
    7. int n;
    8. cin>>n;
    9. double a[100000+10];
    10. double b[100000+10];
    11. double sum=0;
    12. for(int i=1;i<=n;i++)
    13. {
    14. cin>>a[i];
    15. b[i]=floor(a[i]);
    16. sum+=b[i];
    17. }
    18. for(int i=1;i<=n;i++)
    19. {
    20. if(abs(a[i]-b[i])<1e-6)
    21. continue;
    22. if(sum<0)
    23. {
    24. sum++;
    25. b[i]++;
    26. }
    27. else
    28. {
    29. break;
    30. }
    31. }
    32. for(int i=1;i<=n;i++)
    33. {
    34. cout<
    35. }
    36. return 0;
    37. }

  • 相关阅读:
    MAC如何解决idea卡顿问题
    为什么模板的声明与定义不能分离?
    SpringBoot+EasyExcel导入导出【加水印】
    艾美捷ProSci 激活素RIB / ACVR1B重组蛋白方案
    基于日期、时间、经纬度下载MODIS数据并批处理
    基于STM32设计的物流追踪系统(GPS+BC20+华为云IOT)
    MySQL之如何复制一张表的数据
    12款SCADA软件功能比较
    【OpenCV 图像处理 Python版】图像处理的基本操作
    恒合仓库 - 角色管理、启动或禁用角色、为角色分配权限
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126330859