-
[백준] 1085 - 직사각형에서 탈출 (python)Problem Solving/Python 2023. 7. 11. 10:56반응형
1085번: 직사각형에서 탈출
한수는 지금 (x, y)에 있다. 직사각형은 각 변이 좌표축에 평행하고, 왼쪽 아래 꼭짓점은 (0, 0), 오른쪽 위 꼭짓점은 (w, h)에 있다. 직사각형의 경계선까지 가는 거리의 최솟값을 구하는 프로그램
www.acmicpc.net
포인트
주어진 좌표대로 직선을 그어 사각형을 만들었을 때 한수가 가장 빨리 갈 수 있는 경계선을 찾기만 하면 되기 때문에 한수의 위치와 사방의 거리를 확인해 min 함수로 answer 를 갱신해주는 방식을 택했고 정답처리를 받았다
코드
This file contains hidden or 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 charactersx, 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) 반응형'Problem Solving > Python' 카테고리의 다른 글
[백준] 1110 - 더하기 사이클 (python) (0) 2023.07.12 [백준] 1094 - 막대기 (재귀 풀이) (python) (0) 2023.07.11 [백준] 1076 - 저항 (python) (0) 2023.07.10 [백준] 1075 - 나누기 (python) (0) 2023.07.10 [백준] 1037 - 약수 (python) (0) 2023.07.07