#P3432. Maximizing Manhattan Return Path in a Mirror Trap

    ID: 16687 Type: Default 1000ms 256MiB

Maximizing Manhattan Return Path in a Mirror Trap

Maximizing Manhattan Return Path in a Mirror Trap

A mirror trap is a cuboid with mirrored interior surfaces. A miniature laser is placed exactly at the geometric centre (origin) of the trap. The trap has even integer dimensions. Using a Cartesian coordinate system with axes parallel to the edges of the trap, the laser may be aimed at any integer point (including points on the mirror surfaces) except the origin. When fired, the laser beam is reflected by the mirrors (note that the edges and vertices of the cuboid do not reflect) and eventually returns to the laser, possibly from a different direction.

The total Manhattan (city) distance traveled by the beam is defined as the sum of distances covered along the three coordinate axes. In other words, if during a complete cycle the beam travels distances Dx, Dy, and Dz (always non‐negative) in the x, y and z directions respectively, the total distance is

D=Dx+Dy+Dz.D = D_x + D_y + D_z.

Your task is to choose one valid target point such that when the laser is fired in that direction:

  • the beam is reflected by some or all mirrors (but never touches an edge or vertex),
  • the beam eventually returns to the laser, and
  • the total Manhattan distance traveled (over one complete cycle) is maximized.

Note: When the beam is fired in the direction of your chosen target point (p, q, r), reflections occur in each axis at times determined by the ratios \(\frac{L}{|p|}\), \(\frac{W}{|q|}\), and \(\frac{H}{|r|}\) (where L, W, and H are the full lengths of the trap in x, y and z respectively). To ensure the beam does not hit an edge or vertex, the bounce times for any two nonzero directions must be distinct. In particular, if two coordinates are nonzero then we require that $$\frac{L}{|p|} \neq \frac{W}{|q|}, \quad \frac{L}{|p|} \neq \frac{H}{|r|}, \quad \text{and} \quad \frac{W}{|q|} \neq \frac{H}{|r|}.$$

The trap dimensions L, W, and H are provided as even integers. The trap (cuboid) is centered at the origin so that its surfaces lie on planes \(x = \pm L/2\), \(y = \pm W/2\), and \(z = \pm H/2\). The laser (located at (0, 0, 0)) is not a valid target.

Your program will read the trap dimensions and output a valid target point (p, q, r) (three integers separated by spaces) that satisfies the above conditions and maximizes the total Manhattan travel distance of the returning beam. Any solution that meets the requirements is accepted.

## inputFormat

The input consists of a single line containing three even integers L W H (separated by spaces), representing the full dimensions of the mirror trap along the x, y, and z axes respectively. The trap is centered at the origin, so the x-coordinate of the mirror surfaces are at \(x = \pm L/2\) (and similarly for y and z).

## outputFormat

Output three space‐separated integers p q r on a single line. These denote the coordinates of the target point (which must be inside the trap including its surfaces, and not equal to (0,0,0)) such that a laser beam fired from the origin in that direction will be reflected (without ever coinciding with an edge or vertex) and eventually return to the origin while traveling the maximum possible Manhattan distance.

## sample
6 6 6
3 2 1
$$