Cylinder Candy
Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge
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的巧克力,求最后的体积和表面积
分析:
最后的糖块
难点在于求一下图的体积与表面积
接下来就是积分:
附上旋转体的侧面积和体积求法:
介绍一下
这个的求法:
1.可以发现上面的积分就是一个以d为半径四分之一的圆,即2*PI*2*r*(1/4*PI*d*d)
2.替换原理
#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;
struct Node{
int row,col;
int val;
}node[N];
int main() {
int t;
scanf("%d",&t);
while(t--){
double r,h,d;
scanf("%lf%lf%lf",&r,&h,&d);
double temp=PI*(r+d)*(r+d)*h;
double temp1=d*d*d+r*r*d+0.5*PI*d*d*r-(1.0/3.0)*d*d*d;
double s1=2*PI*r*d*(asin(1)-asin(0))+2*PI*d*d;
double temp2=PI*2*(r+d)*h+PI*r*r*2;
double res1=temp+temp1*PI*2,res2=s1*2+temp2;
printf("%0.9lf %0.9lf\n",res1,res2);
}
return 0;
}