题解 | #求解立方根#
求解立方根
http://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca
import sys
num = sys.stdin.readline().strip() sign = 1 if num[0] == "-": sign = -1 n = float(num[1:]) else: n = float(num) if n == 0: print(0.0 * sign) if n == 1: print(1.0 * sign) if n > 1: left, right = 1, n if 0 < n < 1: left, right = n, 1 while left < right: mid = (left + right) / 2 res = mid**3 if mid * mid * mid < n: left = mid elif mid * mid * mid > n: right = mid if round(left,1) == round(right,1): print(round(left, 1) * sign) break