Mirana is an archer with superpower. Every arrow she shoots will get stronger the further it travels. Mirana is currently on the way to warzone.
Since the road is still a long way, Mirana remembers about when she's still in training. In each of her training, Mirana stands on the (0,0) point in a cartesian scale. From that point, she must shoot a circle centered in (x,y) with radius r. Everything happens in z=0.
To maximize the arrow's power, Mirana must shoot the furthest point of the enemy possible. Her arrow travels at the speed of light and will instantly stops the moment it touches the target. On the target, determine the coordinate point that Mirana has to shoot to get maximum power. If multiple coordinate exists, choose the one with the lower x value.
Input
First line is T, number of training (T < 100000). Next T lines each contains 3 space separeted integers x, y, and r for each training (1 < r < x,y < 1000)
Output
For each training, output a line containing the coordinate of the arrow's destination separated by space. Output until 6 digit after decimal point.
Example
Input:3 1 1 1 2 2 1 4 5 2
Output:0.000000 1.000000 1.088562 2.411438 2.126155 5.699076
有一个圆心在(x0,y0),半径是r的圆,要过原点做它的切线,求两个切点中x坐标更小的那个的坐标
解方程……很烦
联立两式:(x-x0)^2+(y-y0)^2=r^2, x^2+y^2=x0^2+y0^2-r^2,得到过两切点的直线方程:
x0x+y0y=x0^2+y0^2-r^2
令k=x0^2+y0^2-r^2,则x0x+y0y=k
上式带入x^2+y^2=k,得到一个x的一元二次方程
(x0^2+y0^2)x^2+(-2kx0)x+(k^2-y^2k)=0
解出来x取小的那个(这肯定有两解的)
然后带回x0x+y0y=k,得到y
这里似乎y会有点精度问题?比如0变成-0.000000
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include