标签:style http color os io ar amp line
题目大意:给定圆柱的R和H,求图中图形的体积。
解题思路:用总的体积减掉重复部分的体积。考虑一个卦限
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const double pi = 4 * atan(1.0);
double f (double R, double x) {
return R * R * x - x * x * x / 3;
}
double solve (double R, double H) {
if (2 * R <= H)
return (f(R, R) - f(R, 0)) * 8;
double h = sqrt(R * R - H * H / 4);
return (H * H * h / 4 + f(R, R) - f(R, h)) * 8;
}
int main () {
double R, H;
while (scanf("%lf%lf", &R, &H) == 2) {
printf("%.4lf\n", R * R * pi * H * 2 - solve(R, H));
}
return 0;
}
uva 1487 - Volume(积分),布布扣,bubuko.com
标签:style http color os io ar amp line
原文地址:http://blog.csdn.net/keshuai19940722/article/details/38727229