Problem Solving/Python
[백준] 1085 - 직사각형에서 탈출 (python)
TakeKnowledge
2023. 7. 11. 10:56
반응형

1085번: 직사각형에서 탈출
한수는 지금 (x, y)에 있다. 직사각형은 각 변이 좌표축에 평행하고, 왼쪽 아래 꼭짓점은 (0, 0), 오른쪽 위 꼭짓점은 (w, h)에 있다. 직사각형의 경계선까지 가는 거리의 최솟값을 구하는 프로그램
www.acmicpc.net
포인트
주어진 좌표대로 직선을 그어 사각형을 만들었을 때 한수가 가장 빨리 갈 수 있는 경계선을 찾기만 하면 되기 때문에 한수의 위치와 사방의 거리를 확인해 min 함수로 answer 를 갱신해주는 방식을 택했고 정답처리를 받았다
코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x, y, w, h = map(int, input().split()) | |
answer = 1001 | |
answer = min(answer, x - 0) | |
answer = min(answer, w - x) | |
answer = min(answer, y - 0) | |
answer = min(answer, h - y) | |
print(answer) |
반응형