• 球的体积并


    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    
    const double pi = acos(-1);
    
    const int MAX = 100 + 10;
    const int inf = 1e9 + 7;
    
    typedef struct {
        double x, y, z, r;
    }Point;
    
    int n;
    Point a[MAX];
    Point s;
    
    //两点之间距离
    double dis(Point p, Point q) {
        double ans = sqrt((p.x - q.x)*(p.x - q.x) + (p.y - q.y)*(p.y - q.y) + (p.z - q.z)*(p.z - q.z));
        return ans;
    }
    
    int main()
    {
            int n=1;
            for (int i = 0; i < n; i++) {
                scanf("%lf%lf%lf%lf", &a[i].x, &a[i].y, &a[i].z, &a[i].r);
            }
            scanf("%lf%lf%lf%lf", &s.x, &s.y, &s.z, &s.r);
            double ans = 0;
            for (int i = 0; i < n; i++) {
                double d = dis(s, a[i]);
                if (d >= s.r + a[i].r ) {
                    continue;
                }
                else if (d + a[i].r <= s.r ) {
                    ans += (4.0 / 3)*pi*a[i].r*a[i].r*a[i].r;
                }
                else if(d+s.r<=a[i].r)
                {
                    ans += (4.0 / 3)*pi*s.r*s.r*s.r;
                }
                else {
                    double co = (s.r*s.r + d * d - a[i].r*a[i].r) / (2.0*d*s.r);
                    double h = s.r*(1 - co);
                    ans += (1.0 / 3)*pi*(3.0*s.r - h)*h*h;
                    co = (a[i].r*a[i].r + d * d - s.r*s.r) / (2.0*d*a[i].r);
                    h = a[i].r*(1 - co);
                    ans += (1.0 / 3)*pi*(3.0*a[i].r - h)*h*h;
                }
            }
            double x=4.0/3.0*pi*(a[0].r*a[0].r*a[0].r+s.r*s.r*s.r);
            printf("%.8lf
    ", x-ans);
        return 0;
    }
  • 相关阅读:
    nodejs 教程
    文摘
    TED字幕摘抄
    Gamma函数相关matlab代码
    js以excel为模板的打印
    ASP.NET动态生成GridView的使用
    IE报错:缺少标识符、字符串或数字
    ExtJS Ext.Ajax.request最好设为同步
    javascript onclick 函数不执行
    Ext.grid.GridPanel数据转json
  • 原文地址:https://www.cnblogs.com/Andromeda-Galaxy/p/10460414.html
Copyright © 2020-2023  润新知