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;
    }
    
    
    
  • 相关阅读:
    PHP获取数组最大值下标的方法
    [转]SpeedPHP微信接口扩展
    SSL证书部署
    Windows server 2003+IIS6+PHP5.4.45环境搭建教程
    运行PHP出现No input file specified错误解决办法
    转载-lvs官方文档-LVS集群中的IP负载均衡技术
    转载-lvs官方文档04-LVS集群的负载调度
    官方文档-Linux服务器集群系统(一)
    转载-lvs官方文档-Linux服务器集群系统(二)
    linux系统参数统计脚本
  • 原文地址:https://www.cnblogs.com/zzhzzh123/p/13385917.html
Copyright © 2011-2022 走看看