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;
    }
    
    
    
  • 相关阅读:
    java的sha1加密,转化为python版本
    VUE:页面跳转时传递参数,及参数获取
    如何使用 Django中的 get_queryset, get_context_data和 get_object 等方法
    django orm 外键id返回对应的名称
    spring boot(一):入门篇
    redis学习(四)——Hash数据类型
    redis学习(三)——List数据类型
    redis学习(二)——String数据类型
    Java多线程(七)——线程休眠
    MySQL和B树的那些事
  • 原文地址:https://www.cnblogs.com/zzhzzh123/p/13385917.html
Copyright © 2011-2022 走看看