This page is still under construction.

Parts of this page are still being built. What you see may change.

The Screen Behind the Mirror

Time limit1sMemory limit128 MB

Summary
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 100100, 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 100100 times.
  • There is at least 11 detector.
  • During the simulation, the laser beam is never collinear with any object.

Input

The first line contains the number of test cases NN. Each test case is given as follows.

  • The first line gives the laser's starting point (x,y)(x, y) and direction vector (i,j)(i, j) in the format "x,y i,j". The starting point lies on the edge of the region. All numbers are integers with −1024≤i,j≤1024-1024 \le i, j \le 1024.
  • The second line gives the number of objects PP. (1≤P≤100)(1 \le P \le 100)
  • Each of the next PP 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 11 to PP in the order they appear in the input.

Output

For each test case, first print "DATA SET #k", where kk is the test case number (starting from 11).

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

Examples1

  1. Example 1

    Input
    1
    50,100 0,-1
    6
    D 0,40 20,20
    M 40,20 60,40
    D 80,20 100,40
    D 0,70 20,90
    S 40,90 60,70
    D 80,90 100,70
    
    Expected output
    DATA SET #1
    1
    6