Putt Party I
Rory and Tony were getting bored doing LeetCodes after solving 4 consecutive medium questions, so they decided to go to a nearby mini-golf course in the city. At this mini-golf course, the course is a two-dimensional plane with a bunch of bumpers of some fixed radius centred at distinct coordinates.
In the game, a ball is always hit from the tee at coordinates with some angle
counted counter-clockwise from the positive
-axis. Rory wants to know for a bunch of different potential shots which of them will hit a bumper eventually and which will go off into the distance forever. If they will hit a bumper eventually, Rory wants to know how far the ball will have travelled before hitting the bumper. Can you help him out so he can finally beat Tony in this game of putt-putt golf.
Input
The first line consists of two integers
and
, the number of bumpers and the radius of each of the bumpers.
The next lines each contain two space-separated integers
and
, the position of the centre of each of the bumpers. It is guaranteed that none of the bumpers intersect the origin.
The next line contains a single integer , the number of different shots that Rory wants to try.
The next lines each contain a single integer
, the angle of the
th shot counter-clockwise from the positive
-axis.
Output
For each of the shots, output if it will hit or miss a bumper.
If it will hit a bumper, output 'HIT' on a line, along with the distance the ball will have travelled before it hits the first bumper. This distance should be rounded to a decimal places.
If it will hit no bumpers, output 'MISS'.
Clarifications
Shots that are tangent to a bumper count as a hit.
Example
Input 1
3 1
3 0
2 2
5 -2
4
0
45
330
90
Output 1
HIT 2.0000
HIT 1.8284
HIT 4.6896
MISS
The case is shown above. The first shot is red, the second shot is purple, the third shot is black, the fourth shot is blue.
The first shot will intersect the bumper centred at . Since it has a radius of
, the intersection point is
which is a distance of
from the origin along the line of travel.
The second shot will intersect the centre of the bumper at . The distance travelled can be calculated to be
.
The third shot will intersect the lower half of the bumper at , having travelled a distance of approximately
.
The final shot will travel straight in the direction, which has no bumper covering it.
Input 2
3 2
4 -2
0 10
-5 -5
3
45
225
0
Output 2
MISS
HIT 5.0711
HIT 4.0000
The case is shown above. Note you see tangents count as a hit here.
Comments