大疆机器学习算法工程师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')


#笔试题目##大疆#
全部评论
lc原题。
点赞
送花
回复 分享
发布于 2020-08-16 20:48
我太迷了,我写的代码完全暴力,全过了,但是我不知道咋过的。。。。脑袋懵
点赞
送花
回复 分享
发布于 2020-08-16 21:07
秋招专场
校招火热招聘中
官网直投

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务