JumpingJackDiv1
TCO18 Fun Round Beijing · 2018-04-20 · by ltdtl
Problem Statement
Jack, your pet frog, is quite a special frog. He usually makes exactly one jump per day. The only exception: once every k days he takes a rest and on that day he does not jump at all.
It is now the morning of day 0. Jack the frog is currently sitting immediately next to your house. Each day at noon Jack makes a decision: If the day number is divisible by k, Jack remains where he is. Otherwise, he jumps dist meters away from your house.
For instance, suppose we have dist=2 and k=2. Jack's journey will look as follows:
- on day 0 Jack stays at your house.
- on day 1 at noon Jack jumps 2 meters away from your house.
- on day 2 Jack remains 2 meters from your house.
- on day 3 at noon Jack jumps another 2 meters away from your house. Thus, he is now 4 meters away from the house.
- on day 4 Jack remains 4 meters from your house,
- on day 5 at noon Jack jumps again and now he is 6 meters away from the house.
- ... and so on.
You are given three positive integers: dist, k, and n. Compute and return the distance between Jack and your house in the evening of day n.
Constraints
- dist will be between 1 and 100, inclusive.
- k will be between 2 and 100, inclusive.
- n will be between 0 and 1,000, inclusive.
2 2 0 Returns: 0
Jack jumps 2 meters and takes a break once every 2 days. In the evening of day 0 he will still be at your house, so the distance between Jack and the house is 0.
2 2 1 Returns: 2
At noon of day 1 Jack jumps 2 meters away from your house. Thus, in the evening of day 1 Jack will be 2 meters away from your house.
2 2 2 Returns: 2
2 2 3 Returns: 4
In this scenario Jack will make two jumps: on day 1 and then on day 3.
2 2 4 Returns: 4
Submissions are judged against all 158 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class JumpingJackDiv1 with a public method int getLocationOfJack(int dist, int k, int n) · 158 test cases · 2 s / 256 MB per case