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

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void work()
{
double x,y,r;scanf("%lf%lf%lf",&x,&y,&r);
if (x*x+y*y<=r*r){puts("0.00000000 0.00000000");return;}
long double k=x*x+y*y-r*r;
long double A=(x*x+y*y),B=-*k*x,C=k*k-y*y*k;
long double delta=sqrt(B*B-*A*C);
long double ansx=min((-B+delta)/(*A),(-B-delta)/(*A)),ansy=sqrt(k-ansx*ansx);
if (fabs(ansx*x+ansy*y-k)>1e-)ansy=-ansy;
double xx=ansx,yy=ansy;
printf("%.8f %.8f\n",xx,yy);
}
int main()
{
int T=read();
while (T--)work();
}

Spoj BLMIRINA

最新文章

  1. MAGENTO - APACHE SOLR INTEGRATION - PART II (SETUP)
  2. unity如何显示血条(不使用NGUI)
  3. AngularJS快速入门指南03:表达式
  4. ubuntu14.04LS中安装SSH
  5. 【转】IT领域技能图谱
  6. Java之webService知识
  7. 被低估的选手 - JavaFx
  8. return和throw某些特性相似
  9. 【AtCoder】ARC074
  10. spring-boot子模块打包去掉BOOT-INF文件夹
  11. NIO小纪
  12. Zookeeper配置文件中的配置项解释和Zookeeper的安装
  13. Python3.5 学习十
  14. PHP 练习(投票)
  15. 201621123005《Java程序设计》第十次实验总结
  16. Numpy入门笔记第二天
  17. Vim使用YouCompleteMe达到类似IDE的代码提示、补全,以及其他实用设置
  18. Eclipse新导入的项目中ctrl+点击指定方法名或类名没有反应,不能跳转问题
  19. 不搭建git服务器对git仓库进行局域网内共享多人合作开发项目
  20. 执行ORACLE SQL时如何 忽略替换变量(转载)

热门文章

  1. 洛谷P1628 合并序列
  2. javascript基本类型和引用类型,作用域和内存问题
  3. 1.JOIN和UNION区别
  4. 2018_oakland_linuxmalware
  5. python_108_格式化字符串format函数
  6. 洛谷 P1126 机器人搬重物 (BFS)
  7. LuoguP1351 联合权值 (枚举)
  8. MySQL常用表结构查询语句
  9. systemverilog之OOP
  10. DNS 网关 子网掩码介绍