You wake up to find yourself in an airless, friction-less, gravity-less arena armed with an object that bounces perfectly off any surface. Targets are appearing at one end of the room and you have to hit as many of them as you can. You can throw the ball directly at a target, or bounce it off the side walls before hitting the target. However, it doesn't count if you hit the wall behind the target before hitting the target.
The diagram below shows three different attempts to hit a target. The two red lines have hit the target, whereas the remaining pink line has missed. The ball always bounces perfectly, which means the angle with which it hits the wall is the same as the angle with which it leaves the wall (one example is shown as below) and it never loses any speed on a bounce.
For specifying locations and speeds, you can consider the arena to be on a Cartesian plane with the origin at the bottom left corner. You can treat the target and walls of the arena as line segments and the ball as a point on the plane.
The input will contain test cases. Each test case consists of lines.
The first line contains integers separated by spaces. These integers represent an arena and a single throw of the ball.
and represent the width and height of the arena .
and represent the initial position of the ball you are throwing and .
and represent the and components of the speed with which you are throwing the ball and .
The next lines each contain integers separated by spaces. Each set of integers represents a possible target. and represent the location of the top of the target and represents its height and and ).
For each test case, your program should output a single line containing an H
or M
character for each of the five targets in the order they appear. Output an H
if the ball would hit the target or M
if it would miss.
Note that the sample data below contains only test cases, but the actual data files will contain each.
Sample Input
116 178 53 41 7 16
43 101 73
32 64 128
13 62 119
23 55 63
44 74 54
137 122 11 24 7 16
20 123 50
30 130 70
15 29 32
23 79 67
12 39 66
Sample Output
MMMHM
HHMHM
Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org
Comments