SHARE
TWEET

Untitled

a guest May 19th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. N = int(input())
  2. trees = []
  3. for i in range(N):
  4.     trees.append([int(i) for i in input().split()])
  5.  
  6. def triangle(n, m):
  7.     return ['.'*(n-1-i+m)+'#'*(i*2+1)+'.'*(n-1-i+m) for i in range(n)]
  8.  
  9. def spruce(n,m):
  10.     tree = []
  11.     for i in range(n):
  12.         tree += triangle(m+i,n-i-1)
  13.     return tree
  14.  
  15. def check_delta(tree1, tree2, delta):
  16.     trees1 = ['.'*len(tree1[0])] + tree1 + ['.'*len(tree1[0])]
  17.     trees2 = ['.'*len(tree2[0])] + tree2 + ['.'*len(tree1[0])]
  18.     new_delta = delta
  19.     for i in range(1, len(trees1)-1):
  20.         delta_i = 0
  21.         for x in trees1[i]:
  22.             if x == '.':
  23.                 delta_i += 1
  24.             else:
  25.                 delta_i = 0
  26.         if delta_i <= new_delta:
  27.             if trees2[i-1][new_delta-delta_i-1] == '#' or trees2[i+1][new_delta-delta_i-1] == '#':
  28.                 new_delta -= 1
  29.                 break
  30.     return new_delta
  31.    
  32. def delta(trees1, trees2):
  33.     delta_min = len(trees1[0])
  34.     for i in range(len(trees2)):
  35.         delta_i = 0
  36.         for x in trees1[i]:
  37.             if x == '.':
  38.                 delta_i += 1
  39.             else:
  40.                 delta_i = 0
  41.         for x in trees2[i]:
  42.             if x == '.':
  43.                 delta_i += 1
  44.             else:
  45.                 break
  46.         if delta_i < delta_min:
  47.             delta_min = delta_i
  48.     return delta_min
  49.  
  50.  
  51.  
  52. def trees_join(trees1, trees2):
  53.     if len(trees1) < len(trees2):
  54.         trees1 += ['.'*len(trees1[0])]*(len(trees2)-len(trees1))
  55.     delt = delta(trees1, trees2)
  56.    
  57.     if len(trees1) > len(trees2):
  58.         trees2 += ['.'*len(trees2[0])]*(len(trees1)-len(trees2))
  59.        
  60.     delt = check_delta(trees1, trees2, delt)
  61.     len_trees = len(trees1[0]) + len(trees2[0]) + 1 - delt
  62.  
  63.     new_tree = []
  64.     for i in range(len(trees1)):
  65.         delta_i = 0
  66.         for x in trees1[i]:
  67.             if x == '.':
  68.                 delta_i += 1
  69.             else:
  70.                 delta_i = 0
  71.         if delta_i == 0:
  72.             tree_str = trees1[i]
  73.         else:
  74.             tree_str = trees1[i][:-delta_i]
  75.         delta_i = 0
  76.         for x in trees2[i]:
  77.             if x == '.':
  78.                 delta_i += 1
  79.             else:
  80.                 break
  81.         new_tree.append(tree_str + '.'*(len_trees - len(tree_str) - len(trees2[i][delta_i:])) + trees2[i][delta_i:])
  82.     return new_tree
  83.    
  84.    
  85. def print_trees(trees):
  86.     for i in trees:
  87.         print(i)
  88.        
  89.        
  90. drawn_trees = spruce(trees[0][0], trees[0][1])
  91. for i in range(1,N):
  92.     tree = spruce(trees[i][0], trees[i][1])
  93.     drawn_trees = trees_join(drawn_trees, tree)
  94. print_trees(drawn_trees)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top