practivceAlgorithm/codeforce
[Codefroce][Python] div.3 #731 - A. Shortest Path with Obstacle
findTheValue
2021. 10. 3. 04:19
점 a에서 b까지의 최소거리를 구하는 문제.
방해물 f가 한개 존재하지만 한개로는 무수히 많은 path를 방해할 수 없다.
방해 가능한 경우의 수는 a와 b와 f가 일직선상에 존재하고 f 가 두 점 사이에 있을 때.
이경우만 예외처리해서 +2 해주면 된다.
import sys
input = sys.stdin.readline
for test in range(int(input())):
input()
a_x, a_y = map(int, input().split())
b_x, b_y = map(int, input().split())
if a_x < b_x:
a_x, b_x = b_x, a_x
if a_y < b_y:
a_y, b_y = b_y, a_y
f_x, f_y = map(int, input().split())
answer = a_x-b_x + a_y-b_y
if a_x == b_x == f_x and a_y > f_y > b_y:
answer += 2
if a_y == b_y == f_y and a_x > f_x > b_x:
answer += 2
print(answer)