Hide

Problem A
Snóker

Languages en is
/problems/snoker/file/statement/en/img-0001.jpg
Photo from flickr.com

Arnar has been watching snooker recently. Snooker is played on a large rectangular table and the players use a cue, which is just a custom made stick. The play area on the table is $140.5$ inches long and $70$ inches wide. There are six pockets on the table, one in each corner and then two others, located on the center of each of the longer sides.

There are also balls on the table in multiple colours and each colour has purpose. The radius of each ball is $1$ inch. The colours are red, yellow, green, brown, blue, pink and black. Additionally, there is a white ball on the table which is the only ball players can hit with their cue. Players then poke one end of the cue into the white ball so that it rolls on the table. It can hit the sides of the table and bounce off of them as well as collide with the other balls. The goal of the game is to hit the white ball into the coloured balls so that they roll into the pockets on the table, known as pocketing balls. Hitting a ball into a pocket grants points, based on the colour, as can be seen in the following table.

Colour

Points

Red

$1$

Yellow

$2$

Green

$3$

Brown

$4$

Blue

$5$

Pink

$6$

Black

$7$

Each time the white ball is hit, a certain colour is designated as the first colour to hit with the white ball, known as the on colour. Each time the correct colour is pocketed by a player, the player gets to hit the white ball again. If there is a red ball on the table when a player starts their turn, then red is the on colour. If the player pockets a red, then they can choose the on colour, except for red, for their next shot. If the player pockets a coloured ball on that shot, then the coloured ball is placed on the table again after points have been awarded. After that shot, the on colour is set to red again.

If the white ball hits the right colour first, then the shot is a HIT. If the white ball hits the wrong colour first, then the shot is a FOUL. If the white ball does not hit any ball, then the shot is a MISS. Note that the white ball can hit the sides of the table as many times as possible, both before hitting a ball, and after.

One of the goals of the game is to snooker the opponent, by hitting the white ball so it is poorly placed for the opponent. At that point it can prove difficult to hit a correct ball, and a direct shot may not be possible. The white ball is then usually shot so that it bounces off the sides of the table before hitting a ball. Since it can be difficult to visualize the bounces, Arnar wants you to tell him whether the white ball hits a correct ball.

You are given the current state of the table, the on colour and a description of how the white ball will travel after being hit with the cue. Determine whether the shot is a HIT, a FOUL, or a MISS. To simplify the task, you may assume there are no pockets on the table, so the white ball cannot be pocketed, but rather always bounces off the sides upon hitting them.

Input

The first line of input contains a single integer $n$, where $2 \leq n \leq 22$, representing the number of balls on the table. Then $n$ lines follow. Each line consists of the colour of the ball and two real numbers $x_ i$, where $1 \leq x_ i \leq 69$, and $y_ i$, where $1 \leq y_ i \leq 139.5$, which represent the position of $i$-th ball. Then a line with the on colour follows. Finally, the input ends with a line consisting of two space separated real numbers $v_ x$ and $v_ y$, where $-1\, 000 \leq v_ x, v_ y \leq 1\, 000$, which represent the distance the white ball will travel on each axis.

The colours of the balls are described by the strings white, red, yellow, green, brown, blue, pink and black. There can be up to $15$ red balls on the table, but at most $1$ of each of the other colours. The white ball will always be on the table, as well as at least one ball with the same colour as the on colour. The position of each ball is given as the distance from the top left corner of the table and the center of the ball, in inches. The top left corner is therefore at the position $(0, 0)$ and the bottom right is at $(70, 140.5)$. You may assume the balls do not intersect, but they may touch. The white ball however will not touch any ball initially. All real numbers are given with exactly three digits after the decimal point.

Output

Output HIT if the white ball hits the correct colour first, FOUL if the white ball hits the wrong colour first, or MISS if the white ball does not hit any ball. You may assume the answer will not change if the positions of the balls change by less than $10^{-3}$ inches and therefore the answer is never ambiguous.

Scoring

Group

Points

Constraints

1

30

The white ball does not travel far enough to reach a side of the table. Either $v_ x = 0$ or $v_ y = 0$.

2

20

Either $v_ x = 0$ or $v_ y = 0$.

3

25

The white ball does not travel far enough to reach a side of the table.

4

25

No further constraints.

Explanation of samples

The first sample belongs to group $1$. The answer is HIT because the white ball hits the black ball first.

\includegraphics[width=0.7\textwidth ]{sample1}
Figure 1: Sample 1

The second sample belongs to group $2$. The white ball bounces of the bottom side and then travels up the table. The answer is FOUL because the white ball hits the pink ball first.

\includegraphics[width=0.7\textwidth ]{sample2}
Figure 2: Sample 2

The third sample belongs to group $3$. The white ball goes between the green ball and the brown ball. The answer is FOUL because the white ball hits the blue ball first.

\includegraphics[width=0.7\textwidth ]{sample3}
Figure 3: Sample 3

The fourth sample belongs to group $4$. The white ball first travels between the brown ball and the yellow ball, bounces off the bottom side and then the left side. Then the white ball travels past the green ball, bounces off the top side and then travels between the green ball and the brown ball. Finally the white ball bounces off the bottom side and then comes to a stop near the right side. The answer is MISS because the white ball did not hit any ball before coming to a stop.

\includegraphics[width=0.7\textwidth ]{sample4}
Figure 4: Sample 4
Sample Input 1 Sample Output 1
2
white 35.000 1.000
black 35.000 29.000
black
0.000 50.000
HIT
Sample Input 2 Sample Output 2
3
white 35.000 80.000
black 35.000 29.000
pink 34.000 40.000
black
0.000 1000.000
FOUL
Sample Input 3 Sample Output 3
7
white 30.000 28.000
green 23.500 29.000
brown 35.000 29.000
yellow 46.500 29.000
blue 35.000 70.250
pink 35.000 105.500
black 35.000 127.750
yellow
10.000 100.000
FOUL
Sample Input 4 Sample Output 4
22
black 35.000 127.727
pink 35.000 105.375
blue 35.000 70.250
brown 35.000 28.100
green 23.333 28.100
yellow 46.667 28.100
red 35.000 107.625
red 33.998 109.362
red 36.002 109.362
red 32.995 111.099
red 35.000 111.099
red 37.005 111.099
red 31.992 112.836
red 33.998 112.836
red 36.002 112.836
red 38.008 112.836
red 30.990 114.573
red 32.995 114.573
red 35.000 114.573
red 37.005 114.573
red 39.010 114.573
white 39.550 24.440
red
-104.181 431.898
MISS

Please log in to submit a solution to this problem

Log in