#C14752. Robot Energy Collection Simulation

    ID: 44436 Type: Default 1000ms 256MiB

Robot Energy Collection Simulation

Robot Energy Collection Simulation

A robot is placed in an 8×8 grid starting at cell (1, 1). Its goal is to collect 10 energy units by visiting cells in a special energy area and then to reach the teleporter at cell \( (8,8) \). The energy area is defined as all cells \( (i,j) \) satisfying \(3 \le i \le 6\) and \(3 \le j \le 6\). Each move, the robot randomly chooses one of the four directions: up, down, left, or right, and moves one cell if the destination is within the grid boundaries. When it enters a cell in the energy area, it collects 1 energy unit. However, if the robot reaches the teleporter before collecting 10 energy units, it is immediately teleported back to the start at (1, 1) and must continue its mission.

Your task is to simulate the robot's movement based on the above rules. There are two modes:

  • simulate: Perform a single simulation and print the number of moves taken.
  • expected: Given an integer \(n\) (number of simulations), run the simulation \(n\) times and output the expected number of steps as a floating point number rounded to 6 decimal places.

Note: For the purpose of deterministic output, you should re-seed the random number generator with 42 at the beginning of each simulation. All input should be read from standard input and all output printed to standard output.

inputFormat

The input consists of a single line. The first token is a string that is either simulate or expected. If the token is expected, it is followed by an integer \(n\) representing the number of simulations to perform.

outputFormat

If the mode is simulate, output a single integer representing the number of moves taken by the robot to collect 10 energy units and reach the teleporter at \( (8,8) \). If the mode is expected, output a floating point number (rounded to 6 decimal places) representing the average number of steps over \(n\) simulations.

## sample
simulate
82

</p>