Introduction
Codeforces 791A, also known as "Bear and Big Brother," presents a simple yet intriguing problem that involves the growth rates of two bears, Limak and Bob. In this article, we'll dissect the provided Python code to unravel the story behind their growth and explain the logic that determines when Limak surpasses Bob in size.
The Problem Scenario
Imagine two bears, Limak and Bob, with their initial weights represented by the variables 'limak' and 'bob,' respectively. The bears undergo a growth process each year, with Limak growing three times as fast as his current weight and Bob growing twice as fast. The objective is to determine how many years it takes for Limak to become larger than Bob.
The Code Walkthrough
Let's break down the code to understand how it tackles this problem.
limak, bob = input().split()
limak = int(limak)
bob = int(bob)
year_count = 0
while True:
if limak > bob:
print(year_count)
break
else:
limak = 3 * limak
bob = 2 * bob
year_count += 1
Explanation of the Growth
Limak grows three times faster than his current weight, and Bob grows two times faster than his current weight. This leads to Limak catching up and eventually surpassing Bob in size.
Conclusion
In summary, Codeforces 791A captures the playful concept of bear growth, illustrating how the speed of growth influences their relative sizes. The code efficiently simulates this growth process and provides a clear answer to the question of how many years it takes for Limak to become larger than Bob.
0 Comments