GentleBots
Time limit1sMemory limit512 MB
Simulate a fixed three-dimensional two-robot controller: for each robot, print the straight or detour route around the other robot's position, exactly following the stated rules.
- Level
Medium7 of 10
- Topics
- Simulation, Implementation, Geometry, Brute force
- Solved
- No attempts yet
Problem
Rainforest Inc. is opening a large automated warehouse in the north of the UK, in a place called Walthamstow.
The worker robots inside move in three dimensions. In one time step a robot either stays where it is or walks one metre along one of the six axis directions, so a robot that travels from to with nothing in its way needs steps.
The robots are impeccably polite. When two of them meet head on, they settle it without a word and one steps aside so the other can pass.
A robot always stands on integer coordinates. Two robots must never stand on the same coordinates, and two robots must never exchange positions in one time step. All moves of a time step happen at the same instant.
The test run of the warehouse has two robots installed. The controller plans them with one fixed procedure, written out in the output section, and your program has to reproduce that plan exactly.
Input
The first line has six space separated integers . The first three are the start position of robot 1 and the last three are its end position . The second line gives the six values of robot 2 in the same format. Every coordinate satisfies .
The two robots start at different positions and end at different positions. One robot may start and end at the same position.
Output
Print the plan of the controller. Counting from 0, line has six space separated integers: the position of robot 1 at time followed by the position of robot 2 at time . The first line holds the two start positions, the last line holds the two end positions, and between two consecutive lines a robot moves at most one metre.
The controller walks one robot at a time and leaves the other standing. Two definitions come first.
The straight route from to is the list of positions that begins at , changes the x coordinate one step at a time until it matches the x coordinate of , then changes the y coordinate the same way, then the z coordinate, and so ends at .
The safe route from to around a blocked position , where equals neither nor , is fixed like this. If the straight route from to does not contain , that route is the safe route. If it does contain , check the six offsets , , , , , in this order and take the first offset for which the straight route from to does not contain . Such an offset always exists. The safe route is then , every position of the straight route from to , and , in that order.
Write and for the start and the end of robot 1, and and for those of robot 2. The controller applies the first rule whose condition holds.
- If , robot 1 walks the safe route from to around , then robot 2 walks the safe route from to around .
- Otherwise, if , robot 2 walks the safe route from to around , then robot 1 walks the safe route from to around .
- Otherwise robot 2 first steps aside to , where is the first offset in the list above with . Then robot 1 walks the safe route from to around , and finally robot 2 walks the safe route from to around .
While a robot walks a route, print one line for every position of the route except the first one, and the robot that is not walking repeats its position on those lines. A route of a single position prints no line.