• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
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\n",ans+eps);

        }else{
            double V = 2*PI*r*r*h;
            double other = 8*2*r*r*r/3;
            double ans = V-other;
            printf("%.4lf\n",ans+eps);
        }
    }

    return 0;
}

  

 

posted on 2016-08-18 14:10  dwtfukgv  阅读(409)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3