题目描述
注意Python中向上取整和向下取整的写法
样例
向上取整
import math
math.ceil(num)
向下取整
int(nums)
or
math.floor()
四舍五入
print(round(3.1415926,6)) ## 四舍五入后为6位小数
print("%.4f"%3.1415926) ## 四舍五入后为4位小数
Python代码
import math
def game(e):
for i in range(n):
if h[i]>e:
e -= h[i] -e
else:
e += e-h[i]
if e<0:
return False
return True
if __name__ =='__main__':
n = int(input())
h = list(map(int,input().split()))
m = max(h)
l,r = 0,m
while r-l>10**-10:
mid = (l+r)/2
if game(mid) == False:
l = mid
else:
r = mid
print(math.ceil(r))