UFO Cubes in Roswell
Time limit2sMemory limit1024 MB
Given a cube with mirrors at integer points, trace every downward light ray and report how many exit each face and how many deflections they took.
- Level
Medium7 of 10
- Topics
- Simulation, Implementation, Hash map, Geometry
- Solved
- No attempts yet
Problem
Bob and Alice live in Roswell (New Mexico, USA) and have found a strange object left behind by an Unidentified Flying Object (UFO). It is a large cube of side length () pierced with tiny holes, and it shines differently on every face. Some mechanism inside the cube reflects sunlight so that light emerges from some, but not all, of the holes on each face.
The cube contains () double-sided mirrors at distinct integer coordinates. Each mirror is tiny (less than one unit across) and is set at in one of the six orientations below (labelled to ). Each orientation couples two axes and turns a ray by ; a ray travelling along the remaining, unpaired axis (that is, a ray whose direction lies in the mirror's plane) passes straight through without any interaction.
The cube occupies . The Sun is above the cube, so light enters travelling in the direction (downward). One unit of light enters through every integer coordinate of the top face : at each point with and , moving in the direction. There are therefore incoming rays. Each ray travels in a straight line until it meets a mirror that deflects it (), and once no further mirror lies ahead it leaves the cube through one of the six faces.
The six faces are numbered to as follows.
For each face, report how many rays leave through it and the total number of deflections those rays underwent.
Input and Output
The first line contains the size of the cube.
The second line contains the number of mirrors .
Each of the next lines describes one mirror with four integers , , , : the coordinates of the mirror () and its orientation (). No two mirrors share the same coordinates.
The output consists of 12 integers, one per line. They form six groups of two, one group per face in the order . In each group the first integer is the number of rays that leave through that face and the second is the total number of times those rays were deflected.