[백준/파이썬] 13221번 풀이

업데이트:



문제 정보


풀이

문제

The island of Manhattan in New York has a grid-like network of streets, where taxis have to travel in a rectilinear fashion along the north, south, east and west cardinal directions. The distance from one intersection to another is often called the taxicab distance or manhattan distance. This form of geometry was first considered by Hermann Minkowski in 19th century Germany.

Suppose Manhattan is a 100km x 100km grid of streets with street blocks measuring 1km x 1km. …

입력 요약
The first line of the input will be the (x,y) intersection that you are waiting at for a taxi. The second line has a single integer N (1<=N<=100) of the number of available taxis in Manhattan. The next N lines will be the (x,y) positions of taxis around Manhattan. …

출력 요약
The position of the closest taxi to you.

코드

w=list(map(int,input().split()))
print(*sorted([list(map(int,input().split()))for i in range(int(input()))],key=lambda x:abs(w[0]-x[0])+abs(w[1]-x[1]))[0])

설명

핵심은 구현 관점에서 The island of Manhattan in New York has a grid-like network of streets, where taxis have to travel in a rectilinear fashion along the north, south, ea …를 만족하도록 로직을 구성하는 것입니다.

코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.

경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.



다음 읽을거리

관련 허브 페이지에서 같은 주제의 글을 이어서 확인할 수 있습니다.

댓글남기기