二分搜索(浮点数二分)python版本

Acwing 790 数的三次方根

https://www.acwing.com/activity/content/problem/content/824/1/

 

n = float(input())


def binarySearch(L, R):
    while R - L > 1e-8:
        mid = (L + R) / 2
        if mid * mid * mid > n:
            R = mid
        else:
            L = mid
    return L


if n > 0:
    res = binarySearch(0, n)
else:
    res = binarySearch(n, 0)
print('%.6f' % res)

你可能感兴趣的:(二分搜索(浮点数二分)python版本)