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 5Sample Output
32.907950527415 51.155135338077
1141.046818749128 532.235830206285
题意:t 组数据,每组给出一个半径为 r,高为 h 的圆柱体,现要在这个圆柱体基础上在外扩展厚度 d,问扩展完后的体积与表面积
思路:定积分
根据题意,扩展完后的物体主视图如下
那么,该物体可视为如下的切面旋转后得到的旋转体
因此,本题就转化为求该旋转体的体积与面积,很明显要用定积分来求
故而先用定积分求出上半部分的体积与面积,乘以 2 后(下半部分),再加上中间的圆柱体的体积与面积即可
即求下图旋转体的体积与面积
体积:
首先写出圆的公式:
那么有:
由公式
得:
即:
化简得:
令
得:
所以:
然后算柱体的体积:
故总体积为:
面积:
若曲线方程为:
绕 x 轴旋转一周的表面积:
所以:
上下两个圆:
柱体侧面积:
故总面积为:
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;
}