首页 > 大疆机器学习算法工程师B卷
头像
慕夏之星
编辑于 2020-08-16 20:53
+ 关注

大疆机器学习算法工程师B卷

编程题åc了91%,有没有人都对的帮我看看哪些corner case没考虑到?



import math


while 1:
	a=[]  
	s = input()
	if s != "":
		for x in s.split():  
			a.append(int(x))  


	r, circle_x, circle_y, x1, y1, x2, y2 = a
	rec_x, rec_y = (x1+x2)/2, (y1+y2)/2


	distance = math.sqrt((circle_x-rec_x)**2 + (circle_y-rec_y)**2)

	if abs(circle_y - rec_y) == 0:
		distance_2 = (x2 - x1)/2 
	elif abs(circle_x-rec_x) == 0:
		distance_2 = (y2 - y1)/2 
	else:
		tan1 = abs(circle_y - rec_y) / abs(circle_x-rec_x)
		tan2 = (y2 - y1) / (x2 - x1)

		if tan1 < tan2:
			#abs(circle_x-rec_x) / distance = (x2-x1)/2 / distance_2
			distance_2 = distance * (x2-x1)/2 / abs(circle_x-rec_x)
			
		if tan1 >= tan2:
			#abs(circle_y-rec_y) / distance = (y2-y1)/2 / distance_2
			distance_2 = distance * (y2-y1)/2 / abs(circle_y-rec_y)
		
	if distance_2 + r < distance:
		print('False')
		
	else:
		print('True')


全部评论

(2) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

热门推荐