码迷,mamicode.com
首页 > 其他好文 > 详细

ZOJ 5579 Stean

时间:2015-09-12 18:49:00      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

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.

技术分享

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

 

ZOJ 5579 Stean

标签:

原文地址:http://www.cnblogs.com/crackpotisback/p/4803287.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!