标签:实现 btn 拼接 问题 mirror 创建 dem for n+1
for a in range(0,1001): #a for b in range(0,1001):#b for c in range(0,1001):#c if a+b+c == 1000 and a**2+b**2 == c**2: print(a,b,c)
for a in range(0,1001): for b in range(0,1001): c = 1000-a-b if a+b+c == 1000 and a**2+b**2 == c**2: print(a,b,c)
0 500 500
200 375 425
375 200 425
500 0 500
算法得存储量包括:
1.程序本身所占空间。
2.输入数据所占空间。
3.辅助变量所占空间。
输入数据所占空间只取决于问题本身,和算法无关,则只需分析除输入和程序之外得辅助变量所占额外空间。
空间复杂度是对一个算法在运行过程中临时占用得存储空间大小的量度,一般也作为问题规模n得函数,以数量级形式给出,记作:
S(n) = O(g(n))
g(n)的计算规则和时间复杂度一致
def sumOfN(n): theSum = 0 for i in range(1,n+1): theSum = theSum + i ? return theSum ? print(sumOfN(10)) #n+2 ==>O(n)
a=5 b=6 c=10 for i in range(n): for j in range(n): x = i * i y = j * j z = i * j for k in range(n): w = a*k + 45 v = b*b d = 33 ? #3+3n**2+2n+1 ==>n**2==>O(n**2)
O(1) < O(logn) < O(n) < O(nlogn) < O(n^2) < O(n^3) < O(2^n) < O(n!) < O(n^n)
1.[{ ‘name‘:‘xxx‘, ‘score‘:‘xxx‘ },{ ‘name‘:‘xxx‘, ‘score‘:‘xxx‘ },{ ‘name‘:‘xxx‘, ‘score‘:‘xxx‘ }]
2.[{‘name‘: ‘xxx‘, ‘score‘: ‘xxx‘}, {‘name‘: ‘xxx‘, ‘score‘: ‘xxx‘}, {‘name‘: ‘xxx‘, ‘score‘: ‘xxx‘}]
3.[ (‘name‘,‘score‘), (‘name‘,‘score‘), (‘name‘,‘score‘) ] 4.[(‘name‘, ‘score‘), (‘name‘, ‘score‘), (‘name‘, ‘score‘)]
5.{ ‘zhangsan‘:{‘score‘:‘xxx‘}, ‘lisi‘:{‘score‘:‘xxx‘} } 6.{‘zhangsan‘: {‘score‘: ‘xxx‘}, ‘lisi‘: {‘score‘: ‘xxx‘}}
def test01(): alist = [] for i in range(1000): alist += i return alist
def test02(): alist = [] for i in range(1000): alist.append(i) return alist
def test03(): return [i for i in range(1000)]
def test04(): alist = list(range(1000)) return alist
Timer类:该类是timeit模块中专门用于测量python代码的执行速度/时长的。原型为:class timeit.Timer(stmt=‘pass‘,setup=‘pass‘)。
stmt参数:表示即将进行测试的代码块语句。
setup:运行代码块语句时所需要的设置。
timeit函数:timeit.Timer.timeit(number=100000),该函数返回代码块语句执行number次的平均耗时。
from timeit import Timer
def test01(): alist = [] for i in range(1000): alist += [i] return alist
def test02(): alist = [] for i in range(1000): alist.append(i) return alist
def test03(): return [i for i in range(1000)]
def test04(): alist = list(range(1000)) return alist
if __name__ == ‘__main__‘: timer = Timer(‘test01()‘,‘from __main__ import test01‘) t1 = timer.timeit(1000) print(t1)
timer2 = Timer(‘test02()‘,‘from __main__ import test02‘) t2 = timer.timeit(1000) print(t2)
timer3 = Timer(‘test03()‘,‘from __main__ import test03‘) t3 = timer.timeit(1000) print(t3)
timer4 = Timer(‘test04()‘,‘from __main__ import test04‘) t4 = timer.timeit(1000) print(t4) #0.060362724815831825 #0.058856628773583 #0.05833806495468252 #0.05742018511486435
标签:实现 btn 拼接 问题 mirror 创建 dem for n+1
原文地址:https://www.cnblogs.com/cou1d/p/12684875.html