2018EC-Final Interstellar … Fantasy

2018EC-Final Interstellar … Fantasy-F题

链接:https://ac.nowcoder.com/acm/contest/366/F
来源:牛客网

题目描述
Unfortunately, the boy finally got bankrupt. Looking at his receding figure, Rikka understood more about the world — but she is still herself. Though, she still sat on the tower and spent time with the low gravity, feeling lost.

She looked at the deep dark sky, where the blue round Earth is shining overhead. Rikka thought about her families, her friends, and her homeland. Is she in her dream or a ``real’’ world? The girl of chunibyo felt afraid for the first time since the journey began.

She saw a bright star traveling fast around the earth — maybe a geostationary space station. How could she get there? Daydream started again.

In other words, Rikka wonders the minimum distance she needs to travel from her position s to the position of the star t, while a sphere — the earth staying there as an obstacle. They are in a 3-dimensional Euclidean space. s and t may be at the same position.
输入描述:
The first line contains an integer T~(1 \leq T \leq 1000)T (1≤T≤1000), the number of test cases. Then T test cases follow.

Each test case contains two lines.

The first line contains four integers o_x, o_y, o_z, ro
x

,o
y

,o
z

,r, the positions in each dimension of the center of the sphere o and its radius.

The second line contains six integers s_x, s_y, s_z, t_x, t_y, t_zs
x

,s
y

,s
z

,t
x

,t
y

,t
z

, the positions in each dimension of the starting point s and the terminal point t, respectively. Notice that s and t may be at the same position.

It is guaranteed that neither s nor t is strictly inside the obstacle, and each value of a position or a radius in the input belongs to [1, 1000].
输出描述:
Output one number, the minimum distance from s to t without entering the sphere obstacle. Your answer is considered correct if the absolute or relative error doesn’t exceed 10^{-6}10
−6
.

题意:给一个O点的x,y,z坐标。以O为球心然后给两个s,t点。问s,t点的最近距离。我们讨论两种情况。

第一种情况是:直接是两个点的直线距离。
第二种情况是:两个点到球切线的距离再加一个弧的距离。

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+50;
double dis(double x,double y,double z,double xx,double yy,double zz){
    return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy)+(z-zz)*(z-zz));
}
int main(){
    int T; scanf("%d",&T);
    while(T--){
        double ox,oy,oz,r; scanf("%lf%lf%lf%lf",&ox,&oy,&oz,&r);
        double sx,sy,sz,tx,ty,tz; scanf("%lf%lf%lf%lf%lf%lf",&sx,&sy,&sz,&tx,&ty,&tz);
        double st=dis(sx,sy,sz,tx,ty,tz);
        double os=dis(sx,sy,sz,ox,oy,oz);
        double ot=dis(tx,ty,tz,ox,oy,oz);
        double p=(os+ot+st)/2;
        double h=sqrt(p*(p-st)*(p-os)*(p-ot))*2/st;
        double x=acos(h/os)+acos(h/ot)-acos(r/os)-acos(r/ot);
        if(h>=r || os*os>=st*st+ot*ot || ot*ot>=os*os+st*st) { printf("%.9f\n",st);continue; }
        printf("%.9f\n",sqrt(os*os-r*r)+sqrt(ot*ot-r*r)+x*r);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值