赞
踩
#4.1 front为头指针,rear为尾指针 def recursion(li,front,rear): if front==rear or front+1==rear: return max(li[rear],li[front]) return max(recursion(li,front,int((front+rear)/2)),recursion(li,int((front+rear)/2)+1,rear)) print('空间复杂度为n;\n时间复杂度为log2(n^2)\n'+ '过程:log2(n)+log2(n/2)+log2(n/2/2)+···\n'+ '=log2(n)*(1/2+1/2/2+1/2/2/2+···)\n' '=log(n)*lof(n)') #4.6 def text6(n): if n==1: return 1 return text6(n-1)+1/n #4.7 f为头指针,r为尾指针 def text7(s,f,l): if f==l: return 0 return text7(s,f+1,l)+int(s[f])*10**(l-f-1) #4.8 def text8(): print('n/2+n/2/2+···+n/(2^logn)\n=(n/2)*(1+1/2+1/4+1/(2^logn))\n=n/2*log(logn)\n=nlogn') #4.9 f为头指针,r为尾指针 def text9(li,f,r): if f==r or f+1==r: return max(li[f],li[r]),min(li[f],li[r]) front,rear=text9(li,f,int((f+r)/2)),text9(li,int((f+r)/2+1),r) return max(front[0],rear[0]),min(front[1],rear[1]) #4.10 def text10(num,res=0): if num==1: return res return text10(num//2,res+1) #4.11 def text11(li,f,m,r
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。