ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

USU Junior Contest October'2004

About     Problems     Submit solution     Judge status     Standings
Contest is over

B. Fireball

Time limit: 1.0 second
Memory limit: 64 MB
Today almost everybody knows about the scientific research department of the Night Watch, located in Solovetz city. Due to the artful actions of Zavulon (the boss of Day Watch, you know) this Scientific Research Institute for Thaumaturgy and Spellcraft (SCITS) was absolutely declassified and removed from secret list already in 60s.
However this fact had not made any harm to its ability of research work. For example right now 3rd-level wizard Vitka Korneev tests a new battle-spell of fireball in his lab in SCITS. Oh… fireball is such a ball of fire that is used for… m-m-m… for neutralization of undesirable consequences.
New fireball appeared to be just an ingenious invention! First of all due to the incongruence of transgression inside the incub-transformation’s psy-field it has a zero radius. But its greatest characteristic is the ability of remaining stable during the predefined number of collisions with obstacles. This characteristic is called N-stability: fireball is N-stable if it stays stable after N collisions but explodes after (N + 1)th collision. So, you may consider, that N-stable fireball loses one level of stability and becomes (N − 1)-stable after each collision with a wall. For example ordinary fireball is 0-stable. So with this invention it became possible to strike an enemy with fireball after several ricochets from the walls. So the military value of this invention is beyond questions. In addition, new N-stable fireball (N > 0) has quite unusual behavior: After collisions it rebounds only from concrete walls! So, it easily flies through any other obstacles. (The theory ties this fact with the accumulation of bio-emotional energy by all static constructions of living quarters). This fact, as you can guess, causes additional military value of new invention: now it is not necessary to provide clear trajectory for the thrown fireball — it will fly thwough any obstacles before it damages the target.
But it is long way from the first prototype to the mass usage. First of all it is necessary to investigate the trajectory of the fireball flight. The following experiment is prepared for this purpose: in the rectangle room two points A and B are being chosen at random. One wizard stands at the point A and the target is placed at the point B. Wizard creates N-stable fireball while his assistant calculates the direction of throw with the help of special program. The direction of throw is selected such way that thrown fireball rebounds from the walls exactly N times and then hits the target. At the same time it should do this with the shortest trajectory (i.e. as quickly as possible).
So, you are to write this special program for direction calculation. The scientists of SCITS tell that all fireballs rebound from the walls according to the law: “angle of incidence equals angle of reflection”. And after collision with room’s corner it rebounds exactly in the opposite direction. Moreover, the theory of fireballs says that, due to continuity, one collision with corner equals two collisions with walls. So, 2-stable fireball explodes after the second collision if the first was with room’s corner. And finally you may assume that the fireball is a point moving in straight lines with constant velocity.
Problem illustration

Input

The first line contains two numbers — width and length of the room. The second line contains the number NN-stability of fireball. The third line contains four numbers — coordinates of points A and B.
All numbers are integers and are separated by one or more spaces. Points A and B lie inside the room but not on its border. The room’s width and length do not exceed 1000 and are greater than 1. N is between 0 and 10 inclusive.

Output

Angle in degrees (with 2 digits after decimal point), that gives the desired direction of fireball. If there are several such angles your program should output the minimal one.
Angle and coordinates are measured as shown on the figure.

Sample

inputoutput
1000 10
3
101 5 128 8
45.00

Notes

Characters and background are taken from books “Monday Begins on Saturday” (Arkady and Boris Strugatsky) and tetralogy “Night Watch”, “Day Watch”, “Twilight Watch” and “Final Watch” (Sergey Lukyanenko).
Problem Author: Pavel Egorov
Problem Source: The 10th Collegiate Programming Contest of the High School Pupils of the Sverdlovsk Region (October 16, 2004)
To submit the solution for this problem go to the Problem set: 1328. Fireball