列表

详情


NC22428. Interstellar … Fantasy

描述

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 , 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, 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_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 .

示例1

输入:

2
2 1 1 1
1 1 1 3 1 1
2 1 1 1
1 2 2 3 1 1

输出:

3.14159265
2.64517298

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++ 解法, 执行用时: 5ms, 内存消耗: 420K, 提交时间: 2022-07-07 12:17:55

#include<cstdio>
#include<cmath>
int n,m,a,b,c,d,x,y,z,t;
double sx,sy,sz,tx,ty,tz,r,r1,r2,r3,th1,th2,th,ans;
int main()
{
	scanf("%d",&t);
	for(int i=1;i<=t;i++)
	{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	scanf("%d%d%d",&x,&y,&z);
	sx=x-a;
	sy=y-b;
	sz=z-c;
	scanf("%d%d%d",&x,&y,&z);
	tx=x-a;
	ty=y-b;
	tz=z-c;
	r=d;
	r1=sqrt(sx*sx+sy*sy+sz*sz);
	r2=sqrt(tx*tx+ty*ty+tz*tz);
	r3=sqrt((tx-sx)*(tx-sx)+(ty-sy)*(ty-sy)+(tz-sz)*(tz-sz));
	th=(r1*r1+r2*r2-r3*r3)/(2*r1*r2);
	th=acos(th);
	th1=acos(r/r1);
	th2=acos(r/r2);
	if((th2+th1)>=th)ans=r3;
	else ans=(th-th2-th1)*r+sqrt(r1*r1-r*r)+sqrt(r2*r2-r*r);
	printf("%.8lf\n",ans);
	}
}

上一题