zoukankan      html  css  js  c++  java
  • HDU 3668 Volume (数学,积分)

    题意:求图中交叉圆柱体的体积!

    析:大体思路很明确,把两个圆柱的体积加起来 减去中间公共部分的即可!第一步首先得想到公共部分是一个怎样的图形。这个在高数下册例题中有讲到!

    中间实线部分就是第一卦限内的图形,显然一个二重积分就可以搞定:

    这种情况比较简单点,适合于2*R <= h 的时候!

    如果2*R > h话!

    需要加点想象力,中间公共部分 是一个长方体 加上两个小突起

    也是把他分成8份,只算第一卦限内的。

    把他放到坐标系里 与上一个图相比,没什么变换 只是将上一个图沿x轴平移了h/2 个单位,而0~h/2这片区域是一个长方体!

    这样只需改变积分上下限即可!公式不变!

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <stack>
    using namespace std ;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-10;
    const int maxn = 800 + 5;
    const int mod = 1e9 + 7;
    const char *mark = "+-*";
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    int n, m;
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    
    int main(){
        double r,h;
        while(scanf("%lf %lf",&r,&h) == 2){
            if (2*r > h + eps){
                double a = sqrt(r*r-h*h/4);
                double V = 2*PI*r*r*h;
                double other = h*h*a/4 + r*r*r*2/3  + (a)*(a)*(a)/3 - r*r*a;
                double ans = V-8.0*other;
                printf("%.4lf
    ",ans+eps);
    
            }else{
                double V = 2*PI*r*r*h;
                double other = 8*2*r*r*r/3;
                double ans = V-other;
                printf("%.4lf
    ",ans+eps);
            }
        }
    
        return 0;
    }
    

      

  • 相关阅读:
    在linux上通过docker运行容器,通过docker搭建jenkens环境
    linux jdk 安装报错
    UEditor 后台配置项返回格式出错,上传功能将不能正常使用!
    spring boot 项目 freemarker 无法加载static 中 js css 文件 原因(报错404)
    windows mongodb 添加用户
    window连接本地mongodb 报错 mongodb shell was not initiallized
    Zookeeper(四) 客户端shell命令
    Zookeeper(三) 集群搭建
    Zookeeper(二) 安装及配置
    Zookeeper(一) 入门
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5783721.html
Copyright © 2011-2022 走看看