EllysChocolates
TCO17 Warsaw · 2017-03-31 · by espr1t
TCO17 Warsaw · 2017-03-31 · by espr1t · Simple Search, Iteration
Problem Statement
Problem Statement
Have you ever heard the following riddle?
A shop sells one chocolate for one euro.
It also exchanges three chocolate wrappers for a new chocolate.
You have 15 euro. How many chocolates can you eat?
It is said that 90% of the people cannot get the correct answer. Since you are not humans but topcoders, Elly believes that 90% (or even more) of you can solve it. What did you get? The correct answer is 22.
Elly thinks that the problem has too many constants. One euro per chocolate. Three wrappers for a new chocolate. Fifteen euro. It can be made so much more generic! Now the girl has given you the following modified version:
A shop sells one chocolate for P euro.
It also exchanges K chocolate wrappers for a new chocolate.
You have N euro. How many chocolates can you eat?
Given theint s P, K, and N, return the maximum number of chocolates that can be eaten.
A shop sells one chocolate for one euro.
It also exchanges three chocolate wrappers for a new chocolate.
You have 15 euro. How many chocolates can you eat?
It is said that 90% of the people cannot get the correct answer. Since you are not humans but topcoders, Elly believes that 90% (or even more) of you can solve it. What did you get? The correct answer is 22.
Elly thinks that the problem has too many constants. One euro per chocolate. Three wrappers for a new chocolate. Fifteen euro. It can be made so much more generic! Now the girl has given you the following modified version:
A shop sells one chocolate for P euro.
It also exchanges K chocolate wrappers for a new chocolate.
You have N euro. How many chocolates can you eat?
Given the
Constraints
- P will be between 1 and 1,000, inclusive.
- K will be between 2 and 1,000, inclusive.
- N will be between 3 and 1,000,000, inclusive.
Examples
0)
1 3 15 Returns: 22
Elly buys 15 chocolates with the money she has, eats them, and gets 15 wrappers. She then exchanges them for 5 new chocolates. After eating them as well, she has 5 wrappers, 3 of which she exchanges for a new chocolate. After eating it as well, she again has three wrappers, which she exchanges for one last chocolate.
1)
41 4 1337 Returns: 42
2)
666 13 823172 Returns: 1337
3)
666 222 444 Returns: 0
In this case even a single chocolate costs more than the money Elly has, so she's unable to buy any.
4)
1 2 1000000 Returns: 1999999
Submissions are judged against all 102 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class EllysChocolates with a public method int getCount(int P, int K, int N) · 102 test cases · 2 s / 256 MB per case