zoukankan      html  css  js  c++  java
  • ZJU-ICPC Summer 2020 Contest 9 B

    B. Ball
    In Geometry, a spherical cap is a portion of a sphere cut off by a plane. If the radius of the sphere is (r) and the height of the spherical cap is (h), the volume of the spherical cap is (πh^{2}(r−frac{1}{3}h)).

    There are two spheres in the three-dimensional space whose radius are (r_1) and (r_2), center coordinates are ((x1,y1,z1)) and ((x2,y2,z2)). Your task is to calculate the volume of their combination.

    Input
    The first line contains four integers, denoting (x1, y1, z1, r1(0 leq x1,y1,z1,r1leq 100)).

    The second line contains four integers, denoting (x2, y2, z2, r2(0 leq x2,y2,z2,r2 leq 100)).

    Output
    Output one line with one real number, the volume of their combination.

    Your answer will be consider correct if its absolute or relative error will not exceed (10^{−6}).

    Examples

    inputCopy
    0 0 0 4
    3 4 0 3
    outputCopy
    361.911473693544167

    inputCopy
    0 0 0 5
    3 0 0 3
    outputCopy
    538.521340702850352

    求两个球体并起来的体积。

    首先分三种情况:包含,分离,相交。

    前两种利用球体公式,后一种用题目给的球冠公式做。

    
    #include<bits/stdc++.h>
    using namespace std;
    
    const long double pi = acos(-1);
    
    long double getans(long double r,long double h){
        return pi * h * h * (3 * r - h);
    }
    long double get(long double r){
        return 4 * pi * r * r * r;
    }
    
    long double ax,ay,az,bx,by,bz,ar,br;
    
    int main(){
        cin >> ax >> ay >> az >> ar;
        cin >> bx >> by >> bz >> br;
        
        long double dis = (ax - bx) * (ax - bx) + (ay - by) * (ay - by) + (az - bz) * (az - bz);
        
        if(dis >= (ar + br) * (ar + br)){
            printf("%.15Lf
    ",(get(ar) + get(br)) / 3.0);
            return 0;
        }
        
        dis = sqrt(dis);
        
        if(dis + ar <= br || dis + br <= ar){
            printf("%.15Lf
    ",get(max(ar,br))/3.0);
            return 0;
        }
        
        long double x = ar * ar - br * br + dis * dis; x = x / (2 * dis); 
        long double y = dis - x;
        
        printf("%.15Lf
    ",(getans(ar,ar + x) + getans(br,br + y)) / 3.0);
        return 0;
    }
    
    
    
  • 相关阅读:
    C#.NET常见问题(FAQ)-浮点数如何四舍五入
    C#.NET常见问题(FAQ)-方法参数带ref是什么意思
    C#.NET常见问题(FAQ)-list比数组效率低多少
    C#.NET常见问题(FAQ)-如何输出带选项的MessageBox,YESNO
    微软企业库Unity学习笔记
    微软企业库5.0---缓存模块
    学习微软企业库--日志模块
    学习微软企业库存心得--总结
    C#获取网页内容,并且处理正确编码
    C#获取网页内容的三种方式
  • 原文地址:https://www.cnblogs.com/zzhzzh123/p/13385917.html
Copyright © 2011-2022 走看看