Cylinder Candy(ZOJ-3866)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011815404/article/details/89977924

Problem Description

Edward the confectioner is making a new batch of chocolate covered candy. Each candy center is shaped as a cylinder with radius r mm and height h mm.

The candy center needs to be covered with a uniform coat of chocolate. The uniform coat of chocolate is d mm thick.

You are asked to calcualte the volume and the surface of the chocolate covered candy.

Input

There are multiple test cases. The first line of input contains an integer T(1≤ T≤ 1000) indicating the number of test cases. For each test case:

There are three integers r, h, d in one line. (1≤ r, h, d ≤ 100)

Output

For each case, print the volume and surface area of the candy in one line. The relative error should be less than 10-8.

Sample Input

2
1 1 1
1 3 5

Sample Output

32.907950527415 51.155135338077
1141.046818749128 532.235830206285

题意:t 组数据,每组给出一个半径为 r,高为 h 的圆柱体,现要在这个圆柱体基础上在外扩展厚度 d,问扩展完后的体积与表面积

思路:定积分

根据题意,扩展完后的物体主视图如下

扫描二维码关注公众号,回复: 6222436 查看本文章

那么,该物体可视为如下的切面旋转后得到的旋转体

因此,本题就转化为求该旋转体的体积与面积,很明显要用定积分来求

故而先用定积分求出上半部分的体积与面积,乘以 2 后(下半部分),再加上中间的圆柱体的体积与面积即可

即求下图旋转体的体积与面积

体积:

首先写出圆的公式:(x-r)^2+y^2=d^2

那么有:x=f(y)=\sqrt{d^2-y^2}+r

由公式 V=\pi \int ^d_0x^2dy

得:V_1=\pi \int_0^d{(\sqrt{d^2-y^2}+r)}^2dy

即:V_1=\pi \int_0^d{(d^2+2r\sqrt{d^2-y^2}-y^2+r^2)}dy

化简得:V_1=\pi d^3+\pi r^2d-\frac{1}{3}\pi d^3+\pi\int_0^d{2r\sqrt{d^2-y^2}}dy

令 y=dsin\theta

得:\pi\int_0^d{2r\sqrt{d^2-y^2}}dy=\int_0^{\frac{\pi}{2}}d^2cos ^2 \theta d\theta= d^2\int_0^\pi \frac{cos2\theta+1}{4}d2\theta=\frac{1}{4}\pi d^2

所以:V_1=\pi r^2d+\frac{2}{3}\pi d^3+\frac{1}{4}\pi d^2

然后算柱体的体积:V_2=\pi(r+d)^2h

故总体积为:V=2V_1+V_2

面积:

若曲线方程为:y=f(x)

绕 x 轴旋转一周的表面积:S=2\pi \int_a^bf(x)\sqrt{1+f'(x)^2}dx

所以:S_1=2\pi \int_0^d(\sqrt{d^2-y^2}+r)\sqrt{1+\frac{y^2}{d^2-y^2}}dy=2\pi d^2+\pi ^2dr

上下两个圆:S_2=2\pi r^2

柱体侧面积:S_3=2\pi (r+d)h

故总面积为:S=2*S_1+S_2+S_3

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 4000000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
int main() {
    int t;
    scanf("%d",&t);
    while(t--){
        double r,h,d;
        scanf("%lf%lf%lf",&r,&h,&d);

        double V1=(d*d*d+r*r*d+0.5*PI*d*d*r-(1.0/3.0)*d*d*d)*PI;
        double V2=PI*(r+d)*(r+d)*h;

        double S1=2*PI*d*d+PI*PI*d*r;
        double S2=2*PI*r*r;
        double S3=2*PI*(r+d)*h;
        double V=2*V1+V2,S=2*S1+S2+S3;
        printf("%0.9lf %0.9lf\n",V,S);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/u011815404/article/details/89977924
ZOJ