牛客第二场F题

牛客第二场F题

 

 

#include<bits/stdc++.h>
using namespace std;
double x[10001],y[10001],z[10001],r1,r2,k1,k2,ju,R,ans;
const double pi=acos(-1);
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        for(int i=0;i<4;i++)
        {
            cin>>x[i]>>y[i]>>z[i];
        }
        cin>>k1>>k2;
        r1=sqrt((x[0]*x[0]-k1*k1*x[1]*x[1]+y[0]*y[0]-k1*k1*y[1]*y[1]+z[0]*z[0]-k1*k1*z[1]*z[1])/(k1*k1-1)+(k1*k1*x[1]-x[0])*(k1*k1*x[1]-x[0])/(k1*k1-1)/(k1*k1-1)+(k1*k1*y[1]-y[0])*(k1*k1*y[1]-y[0])/(k1*k1-1)/(k1*k1-1)+(k1*k1*z[1]-z[0])*(k1*k1*z[1]-z[0])/(k1*k1-1)/(k1*k1-1));
        r2=sqrt((x[2]*x[2]-k2*k2*x[3]*x[3]+y[2]*y[2]-k2*k2*y[3]*y[3]+z[2]*z[2]-k2*k2*z[3]*z[3])/(k2*k2-1)+(k2*k2*x[3]-x[2])*(k2*k2*x[3]-x[2])/(k2*k2-1)/(k2*k2-1)+(k2*k2*y[3]-y[2])*(k2*k2*y[3]-y[2])/(k2*k2-1)/(k2*k2-1)+(k2*k2*z[3]-z[2])*(k2*k2*z[3]-z[2])/(k2*k2-1)/(k2*k2-1));
        ju=((k1*k1*x[1]-x[0])/(k1*k1-1)-(k2*k2*x[3]-x[2])/(k2*k2-1))*((k1*k1*x[1]-x[0])/(k1*k1-1)-(k2*k2*x[3]-x[2])/(k2*k2-1))+((k1*k1*y[1]-y[0])/(k1*k1-1)-(k2*k2*y[3]-y[2])/(k2*k2-1))*((k1*k1*y[1]-y[0])/(k1*k1-1)-(k2*k2*y[3]-y[2])/(k2*k2-1))+((k1*k1*z[1]-z[0])/(k1*k1-1)-(k2*k2*z[3]-z[2])/(k2*k2-1))*((k1*k1*z[1]-z[0])/(k1*k1-1)-(k2*k2*z[3]-z[2])/(k2*k2-1));
        ju=sqrt(ju);
        if(r1+r2<=ju)
        {
            cout<<0<<endl;
        }
        else if(min(r1,r2)+ju<=max(r1,r2))
        {
            R=min(r1,r2);
            ans=4.00*pi*R*R*R/3.00;
            printf("%.3lf\n",ans);
        }
        else
        {
            double ca=(r2*r2+ju*ju-r1*r1)/(2*r2*ju);
            double h1=r2-r2*ca;
            double h2=(r1+r2-ju)-h1;
    
        
            double v1,v2;
            v1=pi*r2*h1*h1-pi*h1*h1*h1/3.00;
            v2=pi*r1*h2*h2-pi*h2*h2*h2/3.00;
            ans=v1+v2;
            printf("%.3lf\n",ans);
        
        }
    }
    return 0;
}

 

 

 

上一篇:【NOIP2013中秋节模拟】表白(love) 题解


下一篇:类欧几里得算法 重学笔记