TopcoderArchiveVisit Topcoder
SRM26 Jan 2020
SRM 777

LimpingDog

Problem statement, definition, constraints, and public examples.

Problem Statement

A limping dog is walking forward. The dog moves one leg at a time, in the following cyclic order: right rear, right front, left rear, left front.

The dog's left rear leg is injured and moving it takes two seconds. A step with any other leg takes only one second.

After every 47 completed steps the dog takes a 42-second break.

You are given the int time. Return the number of steps the dog has completed in the given time.

Definition

Class:
LimpingDog
Method:
countSteps
Parameters:
int
Returns:
int
Method signature:
int countSteps(int time)
(be sure your method is public)

Constraints

  • time will be between 0 and 10^6, inclusive.

Examples

  1. 2
    Returns: 2
    In the first two seconds the dog made one step with his right rear leg and one step with his right front leg.
  2. 3
    Returns: 2
    After three seconds the dog is in the middle of stepping with his injured left rear leg. Thus, the number of completed steps is still only 2.
  3. 6
    Returns: 5
    In six seconds the dog made five steps: one with each leg, and then again one with the right rear leg.
  4. 80
    Returns: 47
    The dog has made the first 47 steps and it is now right in the middle of its first 42-second rest.
  5. 104
    Returns: 50
    The dog finished its first rest and then it made three more steps. Note that the rest does not reset the order in which the dog moves its legs. The last leg moved before the rest was the injured left rear leg, so the first three steps after the rest are the left front, right rear, and right front leg (taking one second each).
  6. 806000
    Returns: 376000
    The dog has just finished resting and it is ready to take another step.
  7. 54321
    Returns: 25346
    During the first 54321 seconds the dog has rested 539 times, it completed 25346 steps, and it is now in the middle of moving the injured leg again.
Back to all problems