Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- eastPoints = []
- northPoints = []
- allCows = []
- for i in range(n):
- direction, x, y = input().split()
- x = int(x)
- y = int(y)
- allCows.append([direction, x, y])
- if direction == "E":
- eastPoints.append([i, x, y])
- else:
- northPoints.append([i, x, y])
- ans = ["Infinity"] * n
- for i in range(n):
- minDist = float("inf")
- index = -1
- for j in range(len(allCows)):
- dir1, x_N, y_N = allCows[j]
- for k in range(len(allCows)):
- dir2, x_E, y_E = allCows[k]
- if k != j and dir2 != dir1:
- cj = j, ck = k
- if dir1 == "E":
- storage = x_N
- x_N = x_E
- x_E = storage
- storage = y_N
- y_N = y_E
- y_E = storage
- temp = cj
- cj = ck
- ck = temp
- n_dist = abs(y_N - y_E)
- e_dist = abs(x_N - x_E)
- if y_N < y_E and x_E < x_N:
- if n_dist < e_dist and n_dist < minDist and x_N <= x_E + ans[ck]:
- minDist = abs(y_N - y_E)
- index = cj
- elif e_dist < n_dist and e_dist < minDist and y_E <= y_N + ans[cj]:
- minDist = abs(x_N- x_E)
- index = ck
- if minDist != float("inf"):
- ans[index] = minDist
- for i in range(n):
- print(ans[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement