標籤:
Cylinder CandyTime 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
21 1 11 3 5
Sample Output
32.907950527415 51.1551353380771141.046818749128 532.235830206285
題目連結:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3866
幾何題,加了外層之後可以看作是上下兩個旋轉體加上中間的圓柱體(半徑為r+d),用積分算一下得到公式。
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <string> 5 #include <iomanip> 6 #include <cmath> 7 using namespace std; 8 #define pai acos(-1.0) 9 int T;10 double r, h, d;11 int main(){12 scanf("%d", &T);13 while(T--){14 scanf("%lf%lf%lf", &r, &h, &d);15 double v, area;16 v = (pai*r*d*d*asin(1.0) + pai*(2.0/3.0*d*d*d + r*r*d))*2 + (r+d)*(r+d)*pai*h;17 area = 2*(2*pai*d*d + 2*pai*r*d*asin(1.0)) + 2*pai*r*r + 2*pai*(r+d)*h;18 printf("%.12lf %.12lf\n", v, area);19 }20 21 return 0;22 }
ZOJ 3866 Cylinder Candy