https://codeforc.es/gym/102056/problem/F
思路:1、特批同意点,2、判断st是否经过圆,用海伦公式算出d时角ost后角ots可能时钝角,即s,t在圆心同侧,此时d判断会小于r;3、经过圆时最短路是切线加一段圆弧;(虽说是三维的球,但处理其实是二维
总结:海伦公式:s=sqrt(p*(p-a)*(p-b)*(p-c)) p=(a+b+c)/2;
余弦定理:cos(deg)=v*u/(|v|*|u|);(u,v是向量) 2*a*b*cos(deg(ab) )=a*a+b*b-c*c
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <map>
#include<bits/stdc++.h>
using namespace std;
#define sfi(i) scanf("%d",&i)
#define sfl(i) scanf("%lld",&i)
#define sfs(i) scanf("%s",(i))
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-10
#define PI acos(-1.0)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
/*
//---------------------------------------------------------
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;
*/
//gp_hash_table<string,int>mp2;
//__gnu_pbds::priority_queue<int>q;//因为放置和std重复,故需要带上命名空间
//__gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;//最快
//----------------------------------------------------------
/*
//----------------------------------------------------------
const int BufferSize = 1 << 16;
char buffer[BufferSize], *_head, *_tail;
inline char Getchar() {
if (_head == _tail) {
int l = fread(buffer, 1, BufferSize, stdin);
_tail = (_head = buffer) + l;
}
return *_head++;
}
inline int read() {
int x = 0, f = 1;char c = Getchar();
for (;!isdigit(c);c = Getchar()) if (c == '-') f = -1;
for (;isdigit(c);c = Getchar()) x = x * 10 + c - '0';
return x * f;
}
//----------------------------------------------------------
*/
const int maxn=1e5+9;
const int maxm=4e5+9;
const int mod=998244353;
double dis(double x[],double y[])
{
double ans=0;
for(int i=0;i<3;i++)
{
ans=ans+(x[i]-y[i])*(x[i]-y[i]);
}
return sqrt(ans);
}
double area(double a,double b,double c)
{
double p=(a+b+c)/2.0;
return sqrt(p*(p-a)*(p-b)*(p-c));
}
int main()
{
//FAST_IO;
//freopen("input.txt","r",stdin);
int T;
sfi(T);
while(T--)
{
double o[3],s[3],t[3],r,x[3],y[3];
for(int i=0;i<3;i++) cin>>o[i];
cin>>r;
for(int i=0;i<3;i++) cin>>s[i];
for(int i=0;i<3;i++) cin>>t[i];
double dis_st=dis(s,t);
double dis_os=dis(s,o);
double dis_ot=dis(t,o);
double area_sto=area(dis_st,dis_ot,dis_os);
double d=area_sto*2.0/dis_st;
double deg_sto=(dis_st*dis_st+dis_ot*dis_ot-dis_os*dis_os)/(2*dis_st*dis_ot);
double sto=acos(deg_sto);
double deg_tso=(dis_st*dis_st+dis_os*dis_os-dis_ot*dis_ot)/(2*dis_st*dis_os);
double tso=acos(deg_tso);
if(dis_st==0)
{
printf("0.00000000\n");
continue;
}
if(d-r>eps||sto>=PI/2.0||tso>=PI/2.0)
{
printf("%.8lf\n",dis_st);
}
else
{
double lens=sqrt(dis_os*dis_os-r*r);
double lent=sqrt(dis_ot*dis_ot-r*r);
double cos_st=(dis_os*dis_os+dis_ot*dis_ot-dis_st*dis_st)/(2.0*dis_os*dis_ot);
double deg_st=acos(cos_st);
double cos_os=(r/dis_os);
double deg_os=acos(cos_os);
double cos_ot=(r/dis_ot);
double deg_ot=acos(cos_ot);
double deg=deg_st-deg_os-deg_ot;
double len=deg*r;
//cout<<lens<<" "<<lent<<" "<<len<<endl;
printf("%0.8lf\n",len+lens+lent);
}
}
return 0;
}