Spoj-BLMIRINA Archery Training

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:
31 1 12 2 14 5 2 
Output:
0.000000 1.0000001.088562 2.4114382.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 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<queue>
 8 #include<deque>
 9 #include<set>
10 #include<map>
11 #include<ctime>
12 #define LL long long
13 #define inf 0x7ffffff
14 #define pa pair<int,int>
15 #define mkp(a,b) make_pair(a,b)
16 #define pi 3.1415926535897932384626433832795028841971
17 using namespace std;
18 inline LL read()
19 {
20     LL x=0,f=1;char ch=getchar();
21     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
22     while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
23     return x*f;
24 }
25 inline void work()
26 {
27     double x,y,r;scanf("%lf%lf%lf",&x,&y,&r);
28     if (x*x+y*y<=r*r){puts("0.00000000 0.00000000");return;}
29     long double k=x*x+y*y-r*r;
30     long double A=(x*x+y*y),B=-2*k*x,C=k*k-y*y*k;
31     long double delta=sqrt(B*B-4*A*C);
32     long double ansx=min((-B+delta)/(2*A),(-B-delta)/(2*A)),ansy=sqrt(k-ansx*ansx);
33     if (fabs(ansx*x+ansy*y-k)>1e-8)ansy=-ansy;
34     double xx=ansx,yy=ansy;
35     printf("%.8f %.8f\n",xx,yy);
36 }
37 int main()
38 {
39     int T=read();
40     while (T--)work();
41 }

Spoj BLMIRINA

时间: 2024-08-19 10:52:32

Spoj-BLMIRINA Archery Training的相关文章

UESTC 2014 Summer Training #16 Div.2

虽然被刷了还是要继续战斗下去嗯...就是基础不好,难度相对较大 A.SPOJ AMR10A 点是顺时针给出的,可以在图上画画(脑补也行),连线x-a,x-b(x为选定的一个点,比如第一个点),就把所求面积分成了四部分,a-b左边部分是较容易求出来的, 三角形面积是直接可求,另外两个多边形面积是可以预处理出来的(多个三角形面积和) 反正我是沒想出來...看題解也理解半天,多邊形面積转化为三角形面积和 嗯嗯 #include <iostream> #include <cstdio> #

csu 2014 summer training day 2 莫比乌斯反演

SPOJ VLATTICE 题意:x,y,z<=1000000,x<=a,y<=b,z<=c,给定a.b.c,求gcd(x,y,z)=1的个数 解释:设 f(n)是gcd(x,y,z)=n的种数,F(n)=n|gcd(x,y,z)的种数 那么F(n)=f(n)+f(2n)....=sigm(f(d)){n|d} 那么根据反演公式 f(n)=sigm(u(d/n)*F(d)){n|d} 我们要求的是f(1)=sigm(u(1)*F(n)+u(2)*F(2n)+u(3)*F(3n)..

UESTC 2014 Summer Training #6 Div.2

又是只过两水题,不过状态有些回升,也是差点一血. Problem A SPOJ AMR11A 显然的dp?就一抖就想到尝试从(R,C)推到(1,1),正着推的话,只能检查某一种解可不可行(就有人想出了二分+DP的神奇方法..刚卡过..不过上界是把所有龙加起来..不闲麻烦的话..可以按照贪心的方法先跑一个上界,就每一步选当前最优) 倒着推,龙的话,就加上,药水的话,减去?不够,和1取最大值:某一个点的f[i][j]就是两种策略取最小值: f[i][j] = min{ max(1, f[i+1][j

SPOJ 705 Distinct Substrings(后缀数组)

[题目链接] http://www.spoj.com/problems/SUBST1/ [题目大意] 给出一个串,求出不相同的子串的个数. [题解] 对原串做一遍后缀数组,按照后缀的名次进行遍历, 每个后缀对答案的贡献为n-sa[i]+1-h[i], 因为排名相邻的后缀一定是公共前缀最长的, 那么就可以有效地通过LCP去除重复计算的子串. [代码] #include <cstdio> #include <cstring> #include <algorithm> usi

SPOJ 3273

传送门: 这是一道treap的模板题,不要问我为什么一直在写模板题 依旧只放代码 1 //SPOJ 3273 2 //by Cydiater 3 //2016.8.31 4 #include <iostream> 5 #include <cstring> 6 #include <ctime> 7 #include <cmath> 8 #include <cstdlib> 9 #include <string> 10 #include

Android官方开发文档Training系列课程中文版:手势处理之滚动动画及Scroller

原文地址:http://android.xsoftlab.net/training/gestures/scroll.html 在Android中,滑动经常由ScrollView类来实现.任何超出容器边界的布局都应该将自己内嵌在ScrollView中,以便提供可滚动的视图效果.自定义滚动只有在特定的场景下才会被用到.这节课将会描述这样一种场景:使用scroller显示一种可滚动的效果. 你可以使用Scroller或者OverScroller来收集一些滑动动画所需要的数据.这两个类很相似,但是Ove

SPOJ CRAN02 - Roommate Agreement

题目链接:http://www.spoj.com/problems/CRAN02/ 题目大意:N个数字组成的序列,和为0的连续子序列的个数.N<1e6 解题思路:计算前缀和,统计每个数字出现的次数,那么对于数字sum[i], 如果存在k个sum[i],则代表有C(k, 2)个序列和为0,而如果sum[i] = 0,则还要累加上对应的k值. 代码: 1 ll n; 2 int a[maxn]; 3 ll sum[maxn]; 4 map<int, int> mmp; 5 6 void so

2017 UESTC Training for Data Structures

2017 UESTC Training for Data Structures A    水,找区间极差,RMQ怼上去. #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a;i<=b;i++) #define per(i,b,a) for (int i=b;i&

spoj GCJ1C09C Bribe the Prisoners

题目链接: http://www.spoj.com/problems/GCJ1C09C/ 题意: In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. Cells number i and i+1 are adjacent, and prisoners in adjacent cells are called "neighbours." A wall wi