LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

プログラミング問題集解答例(問24)

Posted at
from math import floor
def question24(k, L):
    lb = 0
    ub = sum(L) / k
    for _ in range(100000):
        mid = (lb + ub) / 2
        if get_num(mid, k, L) >= k:
            lb = mid
        else:
            ub = mid
    return floor(ub * 100) / 100
def get_num(x, k, L):
    num = 0
    for l in L:
        num += floor(l / x)
    return num
n =  3
k =  2
L =  [7.47, 6.66, 4.11]

question24(k, L)
6.66
n =  4
k =  5
L =  [2.86, 2.69, 2.05, 5.23]

question24(k, L)
2.05
n =  5
k =  9
L =  [6.33, 3.18, 6.92, 9.38, 8.96]

question24(k, L)
3.16
n =  6
k =  6
L =  [2.7, 6.85, 9.44, 6.27, 2.83, 5.21]

question24(k, L)
3.42
n =  7
k =  11
L =  [2.16, 6.1, 5.85, 7.76, 9.67, 7.41, 2.29]

question24(k, L)
2.92
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up