ZOJ 5579 Stean

Stean

Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge

Tom is good at making stean, he can make steans of various color and shape. Now he want to know how many water it can contain, and how many material he need to making a stean.

Stean.jpg

The shape of the stean follows rules below:

1. The horizontal projection is a circle. The front projection contains two cosine curve. Tom can pour water from the top of stean.

2.To describe it more clearly, Tom constructs a cylindrical coordinate system. Tom is a strange person, because if there no stean at all when Z1 is equal to Z2, he still asks you. Tom tells you origin of coordinates is on the axis of cylinder , Z-axis is the axis of cylinder. And he measures that the height of undersurface Z1 and the height of upsurface of the stean Z2. And he find the formula of cosine curve is R = 2 + cos(Z).Here R is the inner circle's radius.

Now you need to tell him the capacity and the area of internal surface, which are in direct proportional to water tank capacity and material needed. You need to be precise to two digits after float point.

Input

The first line of the input contains a single integer T (1 <= T <= 300), which denotes the number of test cases. Then each line contains a case, consisted by a pair of integer numbers Z1 and Z2 (|Z1| <= 1000.00, |Z2| <= 1000.00). They are separated by a space.

Output

There are T lines, each line contains a floating point number, the capacity and the area of internal surface. An answer with absolute error less than 10-2 or with relative error less than 10-5 will be accepted.

Sample Input

2
0 3.14159
-0.0001 0.0

Sample Output

44.41 76.28
0.00 28.27





Author: WANG, Xinglu

 

解题:直接积分,注意$Z_1 与 Z_2$的大小,体积可以负,表面积不能负
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const double PI = acos(-1);
 4 double FUCK(double z) {
 5     return PI*(4*z + 4*sin(z) + z/2 + sin(2*z)/4);
 6 }
 7 double f(double z) {
 8     double tmp = 2*PI*(2 + cos(z))*sqrt(1 + sin(z)*sin(z));
 9     return tmp;
10 }
11 double simpson(double a,double b,int n = 10000) {
12     const double h = (b - a)/n;
13     double ans = f(a) + f(b);
14     for(int i = 1; i < n; i += 2) ans += 4*f(a+i*h);
15     for(int i = 2; i < n; i += 2) ans += 2*f(a+i*h);
16     return ans*h/3;
17 }
18 int main() {
19     double z1,z2;
20     int kase;
21     scanf("%d",&kase);
22     while(kase--) {
23         scanf("%lf%lf",&z1,&z2);
24         double v = FUCK(z2) - FUCK(z1);
25         double ss = PI*(2 + cos(z1))*(2 + cos(z1));
26         if(z1 > z2) swap(z1,z2);
27         double s = simpson(z1,z2) + ss;
28         printf("%.10f %.10f\n",v,s);
29     }
30     return 0;
31 }
View Code

 

posted @ 2015-09-12 17:29  狂徒归来  阅读(186)  评论(0编辑  收藏  举报