zoukankan      html  css  js  c++  java
  • Make k Equal from Codeforces Round #629 (Div. 3)

    description

    you are given an array and you are asked to make (k) elements of it equal after some operations.

    you can make one of the following operations:

    • take one of the minimum and increase its value by (1)
    • take one of the maximum and subtract (1) from it

    find the minimum number of operations to make it possible.

    breakthough

    this problem involves nothing but implimention. but we can make it elegantly.

    let conclusion comes first, our required answer is
    (ans=min((ansl,ansr),ansmid)) ,where:

    • (ansl) is the needed operations if we choose to share value (a[k]) with no less than (k) elements.
    • (ansr) is the needed operations if we choose to share value (a[n-k+1]) with no less than (k) elements.
    • (ansmid) is the needed operations if we choose to let (k) elements staying right in the middle be the chosen ones(who is exactly among the k numbers chosen)

    most of the times our answer is contributed by (ansl) or (ansr) except some cases like test case number two given by the host, in which both the minimum and maximum are extremely close as well as the chosen one is in between.

    apart from things above there are also some tricks here related to the constraints of the application of each answer, which is amazing to generate or come out。。。

    code to take a reference:https://codeforces.com/contest/1328/submission/74425585

  • 相关阅读:
    JSP作业2017.4.5
    WEB(JSP)下的JDBC操作
    application下的JDBC操作(JSP应用与开发)
    JSP的指令inclue和动作include的区别
    大牛的博客
    seajs
    tomcat配置js压缩
    angular启动过程原理
    java并发编程
    为什么要定义interface和implements
  • 原文地址:https://www.cnblogs.com/reshuffle/p/12588688.html
Copyright © 2011-2022 走看看