반응형
Notice
Recent Posts
Recent Comments
Link
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Archives
Today
Total
06-27 05:21
관리 메뉴

ImJay

[파이썬/Python] 백준 18301번 Rats 본문

Solved.ac - Python/Bronze V

[파이썬/Python] 백준 18301번 Rats

ImJay 2022. 11. 22. 16:10
반응형

[파이썬/Python] 백준 18301번 Rats

 

18301번: Rats

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

www.acmicpc.net


문제

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. Looking up in your statistics textbook, you propose using the Chapman estimator N, given by:

N := ⌊(n1 + 1)(n2 + 1)/(n12 + 1) - 1⌋

where ⌊x⌋ is the floor of a real number x, i.e., the closest integer less than or equal to x.

 

해설

Douglas decides to count the number of rats living in his area.

Douglas 는 그의 마을에 살고 있는 쥐의 수를 세기로 결심했다.

 

on the first day, Douglas manages to capture n1 rats, tag before releasing them.

첫째날, n1 쥐들을 잡아 표시를 하고 풀어줬다.

 

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.

둘째날, n2 쥐들을 잡아 표시를 하고, 첫째날과 겹친 쥐들은 n12 쥐로 표시했다.

 

Douglas is asking for your help to estimate the total number of rats in his area.

n1, n2, n12 쥐를 토대로 전체 쥐의 수를 추정해라. 공식은 다음과 같다.

 

N := ⌊(n1 + 1)(n2 + 1)/(n12 + 1) - 1⌋

where ⌊x⌋ is the floor of a real number x, i.e., the closest integer less than or equal to x.

⌊x⌋ 는 x에서 소수점을 버린 값이다.

 

코드

n1, n2, n12 = map(int, input().split())

print((n1+1) * (n2 + 1) // (n12 + 1) - 1)

풀이

1. n1, n2, n12 를 입력 받는다.

n1, n2, n12 = map(int, input().split())

 

2. 공식에 따라 전체 쥐의 수를 출력한다.

  • Python 에서 // 연산자를 사용하면 나눈 값의 정수 몫, 즉 나눠진 값의 소수점을 버린 정수를 반환한다.
print((n1 + 1) * (n2 + 1) // (n12 + 1) - 1)

 

반응형
Comments