作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
def tuplePyth(n):
list_=[]
for x in range(1, n):
for y in range(x + 1, (n - x) // 2):
for z in range (y + 1, n - x - y):
if smallestTrip(x, y, z)==False:
list_.append([x,y,z])
print (list_)
def pythTrue(a,b,c):
(A,B,C) = (a*a,b*b,c*c)
if A + B == C or B + C == A or A + C == B:
return True
def smallestTrip(a,b,c):
if pythTrue(a,b,c) == True:
if (a+b+c)%12 == 0:
return True
else:
return False
smallestTrip
检查 x,y,z 是否是基本 3,4,5 直角三角形的倍数。
目标是生成所有可能的勾股三元组,其总和小于输入的总和 n。
(这些三元组不能是 (3,4,5) 三角形的倍数。)
这里的复杂度是O(nnlogn)吗?
最佳答案
其他函数的复杂度为 O(1),并且对于原始问题中的 n
存在三个循环。所以复杂度是 O(n * n * n) = O(n^3)
这个问题可能会提供进一步的启发Time complexity of nested for-loop
关于python - 这个毕达哥拉斯三重函数的复杂度是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53141704/
我是一名优秀的程序员,十分优秀!