This page is still under construction.

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

Mirror Illusion

Time limit2sMemory limit512 MB

Summary
Trace a ray from (0.75, 0.25) through a room of double-sided mirrors on unit grid segments until it hits a wall or returns to the start, and report that point in centimeters.
Level

Medium7 of 10

Topics
Geometry, Simulation, Implementation, Hash map
Solved
No attempts yet

Problem

A rich man equipped a square room with mirrors, either for security or just for fun. Each side of the room is eight meters wide. The floor, the ceiling, and the walls are nothing special, but the room can hold any number of mirrors on the walls or as vertical partitions.

Every mirror is one meter wide, as tall as the wall, double-sided, perfectly reflective, and has no thickness.

The poles that hold the mirrors are at the corners of the room, on the walls, and inside the room. Their locations are the 81 lattice points at one-meter intervals. A mirror can be fixed between two poles that are one meter apart. If we represent a pole with the symbol "+", the layout of the room can be drawn as follows.

Let us denote a location on the floor by (x, y) in a rectangular coordinate system. For example, the rectangular coordinates of the four corners of the room are (0,0), (8,0), (0,8), and (8,8). A location (x, y) is in the room if and only if 0 ≤ x ≤ 8 and 0 ≤ y ≤ 8. For integers i and j with 0 ≤ i ≤ 8 and 0 ≤ j ≤ 8, (i, j) denotes the location of a pole.

One day a thief broke into this room, possibly by breaking the ceiling. He stood at (0.75, 0.25) and looked almost toward the center of the room. Precisely, he looked toward the point (1, 0.5), which is at the same height as his eyes. So what did he see at the center of his sight? He saw one of the following.

  • If there were no mirrors, he saw the wall at (8, 7.5).
  • If there was one mirror between the two poles at (8, 7) and (8, 8), he saw the wall at (7.5, 8). (Let us denote the line segment between these two poles by (8, 7)-(8, 8).)
  • If there were four mirrors on (8, 7)-(8, 8), (7, 8)-(8, 8), (0, 0)-(0, 1), and (0, 0)-(1, 0), he saw himself at (0.75, 0.25).
  • If there were four mirrors on (2, 1)-(2, 2), (1, 2)-(2, 2), (0, 0)-(0, 1), and (0, 0)-(1, 0), he saw himself at (0.75, 0.25).

Write a program that reports the location at which the thief saw a wall or himself under the given mirror arrangement.

Input

The input consists of multiple data sets, each representing how the room is equipped with mirrors. A data set is given in the following format.

n
d1 i1 j1
d2 i2 j2
. . .
dn in jn

The first integer n is the number of mirrors, with 0 ≤ n ≤ 144. How the k-th (1 ≤ k ≤ n) mirror is fixed is given by dk and (ik, jk). dk gives the direction of the mirror and is either 'x' or 'y'. If dk is 'x', the mirror is fixed on (ik, jk)-(ik + 1, jk). If dk is 'y', the mirror is fixed on (ik, jk)-(ik, jk + 1). The end of the input is indicated by a negative integer.

Output

For each data set, output the location (x, y) at which the thief saw a wall or himself. Report the location on a single line, with x and y as integers in centimeters separated by one space. No extra lines or spaces are allowed.

Examples1

  1. Example 1

    Input
    0
    1
    y 8 7
    4
    y 8 7
    x 7 8
    y 0 0
    x 0 0
    4
    y 2 1
    x 1 2
    y 0 0
    x 0 0
    -1
    
    Expected output
    800 750
    750 800
    75 25
    75 25