Submit | All submissions | Best solutions | Back to list |
V_AYP2_F - Mirrors |
EspañolDickie likes to play with mirrors on Sundays, and, as he gets bored very fast he decided to use a flash light in a room full of mirrors to see what happens, he saw a lot of lights crossing over the room but he doesn't know why its happening, he wants to know what kind of wicked reflection law is happening here and that's why he called you, given the size of the matrix of mirrors, the position of the flashlight and the direction, you should be able to determine where the light intersects, you may know that:
All the mirrors are located on the walls of the matrix
The direction will change according to the collision of mirrors, that is, if the direction is, by example, south-west and collides to the western wall, the light will change its direction to south-east by logic, the same happens with the light when collides to the northern, southern and eastern wall.
Input details:
You will read four integers H,W,I,J, corresponding, respectively, to the dimension of the matrix (HxW) and the initial position of the flashlight (I,J), after that, read a string S, the string S could contain one of these possibilities, south-west, south-east, north-east, north-west, you can safely assume that there will not be errors when giving the string.
Output details:
Output a pair of numbers (R,S), corresponding to the intersecting point of two light rays.
INPUT
OUTPUT
5 6 1 3 south-east
0 0
Explanation:
Beginning on (1,3) to the south-east, the light collides to (3,5), then, goes to the south-west when it collides in the southern wall (4,4), then it changes the direction to the north-west and then collides at point (0,0), when colliding this point, the light will return by the same place it came, so the intersection is immediate and you should print 0,0
Hint, answers for the other directions are:
south-west: 4 0
north-east: 1 3
north-west: 1 3
Constraints;
1 <= H,W <= 1000
0 <= I < H
0 <= J < W
S = { “south-east”, “south-west”, “north-east”, “north-west” }
Added by: | Venezuelan Programming League |
Date: | 2013-02-02 |
Time limit: | 5s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |