Advertisement
Guest User

Untitled

a guest
May 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. def tree(i, j, width, brunch):
  2.     if brunch <= j**2+1:
  3.         temp = 1
  4.         while temp <= ((width-brunch)//2)+1:
  5.             print(".", end="")
  6.             temp += 1
  7.         temp = 1
  8.         while temp <= brunch:
  9.             print("#", end="")
  10.             temp += 1
  11.         temp = 1
  12.         while temp <= ((width-brunch)//2)+1:
  13.             print(".", end="")
  14.             temp += 1
  15.     else:
  16.         temp = 1
  17.         while temp < width*2:
  18.             print(".", end="")
  19.             temp += 1
  20.  
  21. def algo(N):
  22.     divider = []
  23.     temp = N
  24.     while temp >= 1:
  25.         steps = input()
  26.         steps = steps.split(' ')
  27.         divider.append(steps)
  28.         temp -= 1
  29.    
  30.     row = 1
  31.     max_width = 1
  32.     while True:
  33.          
  34.         for x in range(N):
  35.             i = int(divider[x][0])  #Количество треугольников
  36.             j = int(divider[x][1])  #Размер самого маленького
  37.             width  = j**2-1
  38.             if max_width < width:
  39.                 max_width = width
  40.             brunch = brunchcalck(i, j, row)
  41.             # print("brunch = ", brunch)
  42.             # print("width = ", width)
  43.            
  44.             tree(i, j, width, brunch)
  45.         print("\n")
  46.         row += 1
  47.        
  48.         # print("brunch = ", brunch)
  49.         # print("width = ", width)
  50.  
  51.         if j % 2 == 0:
  52.             if brunch >= j**2+1:
  53.                 break
  54.         else:
  55.             if brunch >= j**2:
  56.                 break  
  57.  
  58. def brunchcalck(i, j, row):
  59.     target_tri_num = 0
  60.  
  61.     max_tri_brunch = j
  62.     for tri_num in range(i-1):
  63.  
  64.         if (max_tri_brunch >= row):
  65.             target_tri_num = tri_num
  66.             break
  67.         else:
  68.             max_tri_brunch +=  j + tri_num
  69.  
  70.     tri_max_size = j
  71.     for tri_num in range(target_tri_num):
  72.         tri_max_size  += tri_num
  73.  
  74.     brunches = (tri_max_size - (max_tri_brunch - row) - 1) * 2 + 1
  75.     if (brunches < 0):
  76.         return row
  77.     else:
  78.         return brunches    
  79.  
  80. N = int(input())
  81. algo(N)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement