[백준/파이썬] 18301번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 18301번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
To celebrate the Lunar New Year of the Rat, Douglas decides to count the number of rats living in his area. It is impossible for him to find all rats, as they tend to be well hidden. However, on the first day of the new year, Douglas manages to capture n1 rats, and marks each of them with an ear tag before releasing them. On the second day of the new year, Douglas captures n2 rats, and observes that n12 of them had been marked during the first day.
Douglas is asking for your help to estimate the total number of rats in his area. …
입력 요약
The input consists of a single line, with three space-separated integers: n1, n2, n12, in that order.
출력 요약
The output should contain a single line with the single integer N.
코드
import sys;read=sys.stdin.readline
import math
a,b,c=map(int,read().split())
print(math.floor((a+1)*(b+1)/(c+1)-1))
설명
핵심은 구현 관점에서 To celebrate the Lunar New Year of the Rat, Douglas decides to count the number of rats living in his area. …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기