Driving the Rover
Time limit1sMemory limit128 MB
Simulate a rover that takes one command per second, tracking its speed, heading, and position, then report the final integer coordinates.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Driving a rover on Mars from Earth is not easy. Signals take a while to reach the rover, and its feedback is far from instantaneous. The rover is also a delicate and expensive vehicle, so it moves slowly and must be given very precise instructions about which motors to use and when. Here we look at a greatly simplified model of driving a rover.
In this model the rover accepts the eight commands FORWARD, BACKWARD, FASTER, SLOWER, STOP, RIGHT, LEFT, and NOOP, which work as follows:
FORWARD: the rover starts rolling forward at a speed of .BACKWARD: the rover starts rolling backward at a speed of .FASTER: if the rover is already rolling forward, its speed increases by , but never above .SLOWER: if the rover is rolling forward, its speed decreases by (if this brings the speed to , the rover stops).STOP: the rover stops moving.RIGHT: the rover turns degrees to the right.LEFT: the rover turns degrees to the left.NOOP: nothing changes.
The commands FORWARD, BACKWARD, RIGHT, and LEFT take effect only if the rover is stopped at that moment; if it is already moving, the command is ignored. Likewise, FASTER and SLOWER take effect only if the rover is rolling forward; otherwise they are ignored.
Each command corresponds to one second of driving: during that second the rover first processes the command and then moves for one second at the resulting velocity. You are given a sequence of commands for consecutive seconds. The rover starts at the point facing up. The coordinate increases from left to right and the coordinate increases from bottom to top. Determine the rover's final location after the seconds.
Input
The first line contains the number of data sets. Then follow data sets, each of the following form:
The first line of a data set contains the number of commands (and seconds) . This is followed by lines, each containing one of the eight commands above, written in uppercase.
Output
For each data set, output a line Data Set x:, where is the data set's number (starting from ). On the next line, output the rover's final integer coordinates in the order x y. Print a single blank line between consecutive data sets (and no blank line after the last data set).