Putt Party II
Rory and Tony are back at it again at the putt-putt golf course. Rory managed to win last time, but Tony is back on the grind to reclaim his throne. This time, they are on a more advanced course. Similarly, the golf course is a two-dimensional plane, with the tee at . This time, however, each bumper has different radii, as there are different difficulties of bumpers in different sections. Additionally, Tony has developed a better aim: instead of just hitting the ball at an integer angle, Tony now hits the ball in the direction of some point in the distance with integer coordinates, so he has more fine-grained control over his shots.
Just like before, Tony wants you to test out his various shots and see which ones will miss all the bumpers, and which ones will intersect, and where, with one of the bumpers. Can you help Tony claim his revenge over the upstart Rory?
Input
The first line consists of a single integer
, the number of bumpers.
The next lines each contain three space-separated integers
,
and
. The position of each of the bumpers are denoted by
and
, while the radius of the
th bumper around its centre is given by
. It is guaranteed that none of the bumpers are repeated or intersect the origin.
The next line contains a single integer
, the number of different shots that Tony wants to try.
The next lines contain two space-separated integers
and
, the coordinates which Tony is aiming his
th shot at. The shot will travel from the tee straight in the direction of this point
for the
th shot. It is guaranteed that
and
are coprime, i.e. they have no common factors besides
.
It is guaranteed that the bumpers will intersect at no more than unique points.
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 4 decimal places.
If it will hit no bumpers, output 'MISS'.
Example
Input 1
3
4 0 2
-5 -5 2
0 10 3
4
2 1
0 -1
0 1
-2 -3
Output 1
HIT 2.6833
MISS
HIT 7.0000
HIT 5.4926
The first shot intersects the bumper centred at at point
, which is at a distance of approximately
from the tee. The second shot is straight in the
direction, which has no bumpers. The third shot is straight in the
direction, which is perfectly centred at the bumper at
. This bumper has a radius of
, so the intersection is
along the ball's path. The fourth shot intersects the bumper at
.
The bumpers and shots are visualised below:
Input 2
3
4 0 2
-5 -5 2
0 10 3
4
2 1
1 -4
0 1
-2 -3
Input 2
9
2 1 1
1 2 1
4 -2 1
2 -3 1
-5 -2 2
-2 -5 2
-3 3 2
-3 3 1
-3 3 3
9
1 1
1 0
0 1
1 -1
3 -2
6 -5
1 -3
-1 -2
-1 3
Output 2
HIT 1.4142
HIT 2.0000
HIT 2.0000
HIT 2.8284
HIT 3.6056
MISS
HIT 3.1623
HIT 3.4172
HIT 1.4709
The bumpers and shots are visualised below:
Comments