Advertisement
a_chn

Untitled

Sep 21st, 2024
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. n = int(input())
  2.  
  3.  
  4. eastPoints = []
  5. northPoints = []
  6. allCows = []
  7.  
  8. for i in range(n):
  9.     direction, x, y = input().split()
  10.  
  11.     x = int(x)
  12.     y = int(y)
  13.  
  14.     allCows.append([direction, x, y])
  15.  
  16.     if direction == "E":
  17.         eastPoints.append([i, x, y])
  18.     else:
  19.         northPoints.append([i, x, y])
  20.  
  21.  
  22. ans = [float("inf")] * n
  23.  
  24. for i in range(n):
  25.     minDist = float("inf")
  26.     index = -1
  27.  
  28.     for j in range(len(allCows)):
  29.  
  30.         for k in range(len(allCows)):
  31.             dir1, x_N, y_N = allCows[j]
  32.             dir2, x_E, y_E = allCows[k]
  33.             if k != j and dir2 != dir1:
  34.                 cj, ck =  j, k
  35.  
  36.                 if dir1 == "E":
  37.                     storage = x_N
  38.                     x_N = x_E
  39.                     x_E = storage
  40.  
  41.                     storage = y_N
  42.                     y_N = y_E
  43.                     y_E = storage
  44.  
  45.                     temp = cj
  46.                     cj = ck
  47.                     ck = temp
  48.                    
  49.                 n_dist = abs(y_N - y_E)
  50.                 e_dist = abs(x_N - x_E)
  51.                 if y_N < y_E and x_E < x_N:
  52.                     if n_dist > e_dist and n_dist < minDist and x_N <= x_E + ans[ck] and ans[cj] == float("inf"):
  53.                         minDist = abs(y_N - y_E)
  54.                         index = cj
  55.                     elif e_dist > n_dist and e_dist < minDist and y_E <= y_N + ans[cj] and ans[ck] == float("inf"):
  56.                         minDist = abs(x_N- x_E)
  57.                         index = ck
  58.     if minDist != float("inf"):
  59.         ans[index] = minDist
  60.  
  61. for i in range(n):
  62.     if ans[i] == float("inf"):
  63.         print("Infinity")
  64.     else:
  65.         print(ans[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement