Advertisement
Guest User

chuj w dupe

a guest
Apr 5th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. #OBLICZA bf
  2. def get_rate(arr):
  3.     res = arr.copy()
  4.     for i in range(len(res)-1,-1,-1):
  5.         if res[i] == "nan":
  6.             res[i] = [[0,0]]
  7.         elif res[i] != "nan" and i*2+2 >= len(res):
  8.             res[i] = [[1,1],0]
  9.         elif res[i] != "nan":
  10.             l = max(res[i*2+1][0])+1
  11.             r = max(res[i*2+2][0])+1
  12.             res[i] = [[l,r],l-r]
  13.             # res[i] = res[i*2+1] + 1 if res[i*2+1] >= res[i*2+2] else res[i*2+2] + 1
  14.     for i in res:
  15.         del i[0]
  16.     return res
  17.  
  18. #ZNAJDUJE NASTĘPNIK
  19. def find_nastepnik(arr,index):
  20.     k = index*2+2
  21.     flag = True
  22.     if k * 2 + 1 < len(arr) and arr[k * 2 + 1] == "nan":
  23.         flag = False
  24.     while k < len(arr) and arr[k] != "nan" and flag == True:
  25.         k = k * 2 + 1
  26.     return k if flag == False else (k-1)//2
  27.  
  28. #ZNAJDUJE POPRZEDNIK
  29. def find_poprzednik(arr,index):
  30.     k = index * 2 + 1
  31.     flag = True
  32.     if k * 2 + 1 < len(arr) and arr[k * 2 + 2] == "nan":
  33.         flag = False
  34.     while k < len(arr) and arr[k] != "nan" and flag == True:
  35.         k = k * 2 + 2
  36.     return k if flag == False else (k-1)//2
  37.  
  38. #DODAJE ELEMENT DO TABLICY
  39. def add_element(arr,el,index=0):
  40.     if el == arr[index]:
  41.         if arr[index*2+2] == "nan":
  42.             arr[index*2+2] = el
  43.         else:
  44.             add_element(arr,el,index * 2 + 2)
  45.     elif el > arr[index]:
  46.         if arr[index*2+2] == "nan":
  47.             arr[index*2+2] = el
  48.         else:
  49.             add_element(arr,el,index * 2 + 2)
  50.     else:
  51.         if arr[index*2+1] == "nan":
  52.             arr[index*2+1] = el
  53.         else:
  54.             add_element(arr,el,index * 2 + 1)
  55.     return arr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement