Java教程

牛客第二场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;
}

 

 

 

这篇关于牛客第二场F题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!