zoukankan      html  css  js  c++  java
  • 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:
    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 #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
    ",xx,yy);
    36 }
    37 int main()
    38 {
    39     int T=read();
    40     while (T--)work();
    41 }
    Spoj BLMIRINA
  • 相关阅读:
    根据EsLint配置WebStorm格式化代码风格
    Vue中使用vant-UI实现移动端自定义省市区三级联动
    Vue中使用Element-UI实现表格跨页多选
    Vue中使用iview-UI实现切换Tab页网络请求优化
    Vue中使用iview-UI按需引入Select组件下拉框无法生效问题
    Vue中使用iview-UI表格样式修改和使用自定义模板数据渲染相关
    Vue中使用Element-UI表单验证相关问题及解决
    Vue 3.0 多页面项目之商家平台练习
    五 创建道路模型(2 道路的挖填方量计算及条件部件)
    五 创建道路模型(1 道路三要素)
  • 原文地址:https://www.cnblogs.com/zhber/p/7153419.html
Copyright © 2011-2022 走看看