The Screen Behind the Mirror
Time limit1sMemory limit128 MB
Simulate a laser beam in a square region bouncing off mirrors and splitting at splitters, and list every detector that absorbs a beam.
- Level
Medium7 of 10
- Topics
- Geometry, Simulation
- Solved
- No attempts yet
Problem
The demon Park Seung-won is looking for the most powerful laser in the world and has hired you for the task. You have a laser prototype, but before you can receive a budget to build it, you must show Park Seung-won a simulation.
The simulation begins by placing "mirrors", "beam splitters", and "beam detectors" on a 2D plane. Each object is modeled as a line segment.
- Mirror (M): a beam that hits a mirror is reflected across the mirror's segment.
- Detector (D): absorbs any incoming beam.
- Splitter (S): splits an incoming beam into two. One beam passes straight through the splitter with its direction unchanged; the other is reflected across the splitter's segment.
Given a laser fired from a starting point in a given direction, determine which detectors absorb a beam. To simplify the problem, you may assume the following.
- You only need to simulate a square region with side length , and every object lies inside this region.
- The given segments never overlap or touch one another.
- The laser is fired from the edge of the square region.
- The simulation ends once every beam has either left the region or been absorbed by a detector.
- Over the whole simulation, the laser beam is reflected fewer than times.
- There is at least detector.
- During the simulation, the laser beam is never collinear with any object.
Input
The first line contains the number of test cases . Each test case is given as follows.
- The first line gives the laser's starting point and direction vector in the format "x,y i,j". The starting point lies on the edge of the region. All numbers are integers with .
- The second line gives the number of objects .
- Each of the next lines describes one object. The line begins with a character giving the object type — "M" for a mirror, "S" for a splitter, and "D" for a detector — followed by the two endpoints of the segment, each in the format "x,y".
- Objects are numbered from to in the order they appear in the input.
Output
For each test case, first print "DATA SET #k", where is the test case number (starting from ).
If no detector absorbed a beam, print "NO BEAMS DETECTED".
Otherwise, print the numbers of the detectors that absorbed a beam (their object numbers from the input) in ascending order, one per line. Even if the same detector absorbs several beams, print its number only once.
Hint
Enigma - The Screen Behind The Mirror