Cylinder Candy
ZOJ - 3866
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
题意:抽象出来就是求一个圆柱体外面加一层厚度为d的巧克力,求包装完这个立体图形的体积和表面积。
剖析:
以下是包装后的三视图:
所以这道题目的重点就是要求出旋转体的体积和表面积,那么很明显需要用定积分来求,求出后,中间部分就是圆柱形的体积和面积直接可以用公式求得,上下两部分需要用定积分,其推导过程如下:
首先我们需要求旋转体体积和表面积的积分公式如下图:
我们先求旋转体的体积
我们首先可以写出圆的公式
(x−r)2+y2=d2(x−r)2+y2=d2
所以得到
x=f(y)=d2−y2−−−−−−√+rx=f(y)=d2−y2+r
由公式
V=π∫d0x2dyV=π∫0dx2dy
得到 V1=π∫d0(d2−y2−−−−−−√+r)2dyV1=π∫0d(d2−y2+r)2dy
=π∫d0(d2−y2+r2+2rd2−y2−−−−−−√)dy=π∫0d(d2−y2+r2+2rd2−y2)dy
=πd3+πr2d−13πd3+π∫d02rd2−y2−−−−−−√dy=πd3+πr2d−13πd3+π∫0d2rd2−y2dy
=πr2d+23πd3+π∫d02rd2−y2−−−−−−√dy=πr2d+23πd3+π∫0d2rd2−y2dy
令
y=dsinθy=dsinθ
∫d0d2−y2−−−−−−√=∫π20dcosθddsinθ=∫π20d2cos2θdθ∫0dd2−y2=∫0π2dcosθddsinθ=∫0π2d2cos2θdθ
=d2∫π20cos2θ+14d2θ=d2∫0π2cos2θ+14d2θ
=d2∫π0cost+14dt=d2∫0πcost+14dt
=14πd2=14πd2
所以
V1=πr2d+23πd3+14πd2V1=πr2d+23πd3+14πd2
V2=π(r+d)2hV2=π(r+d)2h
V=2V1+V2V=2V1+V2
下面我们来求旋转体的表面积
同样我们由公式如果曲线方程为
y=f(x)y=f(x)
绕x轴旋转一周的表面积
S=2π∫baf(x)1+f′(x)2−−−−−−−−√dxS=2π∫abf(x)1+f′(x)2dx
所以
S1=2π∫d0(d2−y2−−−−−−√+r)1+y2d2−y2−−−−−−−−−−√dyS1=2π∫0d(d2−y2+r)1+y2d2−y2dy
=2πd2+π2dr=2πd2+π2dr
上下两个圆
S2=2πr2S2=2πr2
侧面积
S3=2π(r+d)hS3=2π(r+d)h
S=S1+S2+S3S=S1+S2+S3
然后公式推到出来了,直接照着公式写代码就行了
code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const double pi = acos(-1.0);
int main(){
int t;
scanf("%d",&t);
while(t--){
double r,d,h;
scanf("%lf%lf%lf",&r,&h,&d);
printf("%.10f ",2.0*(2.0/3.0*pi*d*d*d+pi*r*r*d+1.0/2.0*pi*pi*d*d*r)+pi*(r+d)*(r+d)*h);
printf("%.10f\n",2.0*(2.0*pi*d*d+pi*pi*d*r)+2.0*pi*r*r+2.0*pi*(r+d)*h);
}
return 0;
}