#P6039. Optimal Teleportation to Attack the Teacher
Optimal Teleportation to Attack the Teacher
Optimal Teleportation to Attack the Teacher
On an infinite plane (the back mountain), students are initially located at the origin (0,0). Meanwhile, the teacher is at the point (x, y) after picking up a book placed earlier. The students have a special device: from their position they can draw a circle of radius r and throw a teleportation gadget so that it lands on a point S on the circle. At point S, they construct a straight line PQ that is tangent to the circle. The device then teleports the students from their current position to its reflection about the line PQ.
After teleportation, the students must walk from the landing position to the teacher’s location in order to attack. The students are free to choose the radius r and the point S (which determines the tangent line) arbitrarily. Note that if the circle is centered at (0,0) and S = (r cosθ, r sinθ), then the tangent line at S has equation
[ x\cos\theta + y\sin\theta = r, ]
and the reflection of (0,0) about this line is
[ (2r\cos\theta,,2r\sin\theta). ]
The goal is to choose r and \(\theta\) to minimize the walking distance from the teleported point to the teacher's position (x,y), and then, under that optimal scheme, report the value of \(\tan\alpha\), where \(\alpha\) is the angle between the tangent line PQ and the x-axis (with \(\alpha\in[0,180^\circ]\)).
Observe that if we choose \(\theta\) to be the polar angle of the teacher, i.e. with \(\cos\theta=\frac{x}{\sqrt{x^2+y^2}}\) and \(\sin\theta=\frac{y}{\sqrt{x^2+y^2}}\), and set
[ r=\frac{\sqrt{x^2+y^2}}{2}, ]
then the teleported point becomes exactly ((2r\cos\theta,2r\sin\theta)=(x,y)), so the walking distance is 0. Under this optimal scenario, the tangent line is the line tangent to the circle at S. Since the radius OS makes an angle (\theta) with the x-axis, and the tangent line is perpendicular to OS, its angle with the x-axis is (\theta+90^\circ). Hence its tangent is
[ \tan(\theta+90^\circ)=-\cot\theta=-\frac{\cos\theta}{\sin\theta}=-\frac{x}{y},]
provided (y\neq0).
Special cases:
- If (x,y)=(0,0), then the students are already at the teacher's position. In this case, output 0 for both the walking distance and for the tangent value.
- If y=0 and x<>0, the optimal teleportation still makes the walking distance 0. However, the tangent of a vertical line (since \(\theta\) is 0 or \(\pi\)) is not defined. In these cases, output "Infinity" if x>0 and "-Infinity" if x<0 for the tangent value.
Input: Two real numbers x and y separated by space representing the teacher's coordinates.
Output: Print two values separated by a space: the minimum walking distance after using the teleportation device, and the value of \(\tan\alpha\) for the tangent line under the optimal scheme.
inputFormat
The input consists of a single line containing two real numbers x and y (separated by space) which represent the coordinates of the teacher.
outputFormat
Output two values separated by a single space: the minimal walking distance (a non‐negative number) and the value of \(\tan(\theta+90^\circ)\) (see the explanation above). In cases where the tangent is undefined, output the string Infinity
(if positive) or -Infinity
(if negative).
sample
2 2
0 -1