[골드 2] 백준 2381 - 최대 거리 (파이썬)
글 작성자: pental

https://www.acmicpc.net/problem/2381
풀이
N = int(input()) P = [list(map(int, input().split())) for _ in range(N)]
N개의 점을 입력받고 리스트 P에 저장한다.
max_plus = -1e9 min_plus = 1e9 for x, y in P : max_plus = max(max_plus, y + x) min_plus = min(min_plus, y + x)
(x + y)의 최대값 최소값을 계산한다.
max_minus = -1e9 min_minus = 1e9 for x, y in P : max_minus = max(max_minus, y - x) min_minus = min(min_minus, y - x)
(y - x)의 최대값 최소값을 계산한다.
print(max(max_plus - min_plus, max_minus - min_minus))
두 거리 중 더 큰 값을 출력한다.
코드
# 백준 2381 - 최대 거리 # 분류 : 수학 N = int(input()) P = [list(map(int, input().split())) for _ in range(N)] max_plus = -1e9 min_plus = 1e9 for x, y in P : max_plus = max(max_plus, y + x) min_plus = min(min_plus, y + x) max_minus = -1e9 min_minus = 1e9 for x, y in P : max_minus = max(max_minus, y - x) min_minus = min(min_minus, y - x) print(max(max_plus - min_plus, max_minus - min_minus))
이 글은
본 저작자 표시, 비영리 규칙 하에 배포할 수 있습니다. 자세한 내용은 Creative Commons 라이선스를 확인하세요.
Creative Commons
본 저작자 표시
비영리
'Programming > 백준' 카테고리의 다른 글
[플레티넘 5] 백준 3197 - 백조의 호수 (파이썬) (0) | 2025.04.26 |
---|---|
[골드 5] 백준 12919 - A와 B 2 (파이썬) (0) | 2025.04.26 |
[실버 4] 백준 2980 - 도로와 신호등 (파이썬) (0) | 2025.04.25 |
[골드 3] 백준 16437 - 양 구출 작전 (파이썬) (0) | 2025.04.24 |
[골드 1] 백준 2213 - 트리의 독립집합 (파이썬) (0) | 2025.04.24 |
댓글
이 글 공유하기
다른 글
-
[플레티넘 5] 백준 3197 - 백조의 호수 (파이썬)
[플레티넘 5] 백준 3197 - 백조의 호수 (파이썬)
2025.04.26 -
[골드 5] 백준 12919 - A와 B 2 (파이썬)
[골드 5] 백준 12919 - A와 B 2 (파이썬)
2025.04.26 -
[실버 4] 백준 2980 - 도로와 신호등 (파이썬)
[실버 4] 백준 2980 - 도로와 신호등 (파이썬)
2025.04.25 -
[골드 3] 백준 16437 - 양 구출 작전 (파이썬)
[골드 3] 백준 16437 - 양 구출 작전 (파이썬)
2025.04.24
댓글을 사용할 수 없습니다.