#C13424. Elevator System Simulation
Elevator System Simulation
Elevator System Simulation
You are given an elevator system that operates in a building with F floors and E elevators. The elevators are initially idle and start at predefined floors (their initial floor is 0 unless modified). The system accepts commands to request an elevator, update an elevator's current floor manually, or simulate one time step of the system's operation.
The following commands are supported (each command appears on its own line):
SET i f
: Set elevator with id i (0-indexed) to floor f.REQUEST f d
: Request an elevator to move to floor f with the desired direction d (where d is eitherup
ordown
). When a request is made, the system finds the nearest idle elevator or an elevator moving in the correct direction to handle the request.STEP
: Simulate one step. In each step, the system will assign pending requests to available elevators and then update the position of each elevator by one floor in the moving direction (if any). An elevator that is moving will change its current floor by one in the appropriate direction. When an elevator arrives at its target floor, it becomes idle.END
: End of input.
In terms of motion, if an elevator needs to move from its current floor c to a target floor t, then at each step the elevator's floor is updated as follows:
$$\text{current_floor}_{new} = \begin{cases} c+1 & \text{if } t > c,\\ c-1 & \text{if } t < c. \end{cases} $$After processing all commands, output the final floors of all elevators in order of their ids, separated by a space.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains two integers, F and E, where F is the total number of floors and E is the number of elevators.
- The subsequent lines contain commands. Each command is one of the following:
SET i f
REQUEST f d
STEP
END
which signals the end of input.
Note: The commands use 0-indexing for elevator IDs. The simulation ends when the END
command is encountered.
outputFormat
Output the final floor of each elevator (in order of elevator id, from 0 to E-1), separated by a space, to standard output (stdout).
## sample10 1
3
REQUEST 5 up
STEP
STEP
END
2
</p>