eolymp
bolt
Try our new interface for solving problems
Məsələlər

Rational Billiard

Rational Billiard

The International Billiard Manufactory (IBM) builds the best billiard tables in the world. Its last product is the Rational Billiard, which is a friction-less table with volume-less balls. This means that balls just occupy a point in the space, and once they are struck with the cue, they move on the table with constant velocity, until they hit another ball. IBM wants you to build a program to analyse the behavior of balls in the Rational Billiard. The program has to decide whether a ball, struck with certain angle, will hit another ball in certain position. The next figure shows the configuration of the table and the balls: \includegraphics{https://static.e-olymp.com/content/65/65557f51b0967b28e9ccf070f30df165c4f10e63.jpg} \includegraphics{http://uva.onlinejudge.org/external/116/11657img2.png} \textbf{m} and \textbf{n} are integer values that indicate the size of the table. (\textbf{x_1}, \textbf{y_1}) and (\textbf{x_2}, \textbf{y_2}) are the coordinates of the first and second ball respectivelly, with \textbf{0} < \textbf{x_1}, \textbf{x_2} < \textbf{m} and \textbf{0} < \textbf{y_1}, \textbf{y_2} < \textbf{n}. The direction in which the first ball is struck is determined by the integer values \textbf{p} and \textbf{q}. More precisely, the slope determines the hitting direction of the cue, where \textbf{p} and \textbf{q} cannot be zero simultaneously. A value of \textbf{p} = \textbf{0} means that the ball moves parallel to the vertical axis, according to the sign of \textbf{q}. When the ball hits an edge, it rebounds like if the edge were a mirror ( \textit{incidence} \textit{angle} = \textit{reflection} \textit{angle}). In the special case when the ball hits a corner, it is reflected on the same line but in the opposite direction of arrival. Finally, spin effects are neglected, too. \InputFile Each line in the input corresponds to a test case specified by eight integer values: \textbf{m}, \textbf{n}, \textbf{x_1}, \textbf{y_1}, \textbf{x_2}, \textbf{y_2}, \textbf{p} and \textbf{q}, with \textbf{0} < \textbf{m}, \textbf{n ≤ 1000}, \textbf{0} < \textbf{x_1}, \textbf{x_2} < \textbf{m}, \textbf{0} < \textbf{y_1}, \textbf{y_2} < \textbf{n}, \textbf{-1000 ≤ p}, \textbf{q ≤ 1000}, and |\textbf{p}| + |\textbf{q}| > \textbf{0}. The end of the input is specified by a line with the string "\textbf{0 0 0 0 0 0 0 0}". \OutputFile For each test case, the program must output a line with the the text "\textbf{HIT}" if the first ball hits the second ball, or "\textbf{MISS}" if it does not.
Zaman məhdudiyyəti 2 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
4 4 3 1 1 1 1 1
4 4 3 1 2 2 1 1
0 0 0 0 0 0 0 0
Çıxış verilənləri #1
HIT
MISS