快手算法A卷第四题
第四题手抖参数没加参数,过了10%
不知道谁还记得第三个测试用例的答案,看看对不对呀😫😫😫😫😫😫😫😫
from math import pi from random import random from random import uniform a, b, c, d, e, f = input().split(' ') a, b, c, d, e, f = float(a), float(b), float(c), float(d), float(e), float(f) ball_surface_area = 4 * pi dot_num = [0, 0] # 假设共有n个点 n = 10000 for i in range(n): # 球面上选任意一点 x = random() y = uniform(0, 1-x**2) ** 0.5 * (-1 if random() > 0.5 else 1) z = (1 - x**2- y**2) ** 0.5 * (-1 if random() > 0.5 else 1) def is_in_ball(x, y, z): X = (x-a)**2 / d**2 Y = (y-b)**2 / e**2 Z = (z-c)**2 / f**2 return (X+Y+Z) < 1 # 判断在椭球内的点的数量 if is_in_ball(x,y,z): dot_num[0] += 1 else: dot_num[1] += 1 A1 = (dot_num[0] / n) * ball_surface_area A2 = (dot_num[1] / n) * ball_surface_area print(A1, A2)