[백준/파이썬] 15751번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 15751번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
One of the farming chores Farmer John dislikes the most is hauling around lots of cow manure. In order to streamline this process, he comes up with a brilliant invention: the manure teleporter! Instead of hauling manure between two points in a cart behind his tractor, he can use the manure teleporter to instantly transport manure from one location to another.
Farmer John’s farm is built along a single long straight road, so any location on his farm can be described simply using its position along this road (effectively a point on the number line). …
입력 요약
The first and only line of input contains four space-separated integers: $a$ and $b$, describing the start and end locations, followed by $x$ and $y$, describing the teleporter. …
출력 요약
Print a single integer giving the minimum distance Farmer John needs to haul manure in his tractor.
코드
import sys;read=sys.stdin.readline
a,b,x,y=map(int,read().split())
print(min(abs(a-b),abs(a-x)+abs(b-y),abs(a-y)+abs(b-x)))
설명
핵심은 구현 관점에서 One of the farming chores Farmer John dislikes the most is hauling around lots of cow manure. …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기