首页 > 代码库 > poj3929

poj3929

题意:

如上图放置的一个圆锥,告诉你从圆锥顶的洞中流出多少体积的水,求现在水面高度。。

思路:

   无聊时做的一道题,实际上就是一道高数题,重积分,可惜我高数本来也不好而且还忘光了,积了很久,而且错了很多遍。。mark一下。。

   本来还想偷懒最难积分的最后一重想用自适应的simpson积分公式。。无奈精度要求太高一直都是TLE。。

code:

 1 /* 2  * Author:  Yzcstc 3  * Created Time:  2014/10/2 13:59:16 4  * File Name: poj3929.cpp 5  */ 6 #include<cstdio> 7 #include<iostream> 8 #include<cstring> 9 #include<cstdlib>10 #include<cmath>11 #include<algorithm>12 #include<string>13 #include<map>14 #include<set>15 #include<vector>16 #include<queue>17 #include<stack>18 #include<ctime>19 #define repf(i, a, b) for (int i = (a); i <= (b); ++i)20 #define repd(i, a, b) for (int i = (a); i >= (b); --i)21 #define M0(x)  memset(x, 0, sizeof(x))22 #define Inf  0x7fffffff23 #define MP make_pair24 #define PB push_back25 #define eps 1e-826 #define pi acos(-1.0)27 typedef long long LL;28 using namespace std;29 double H, D, V;30 double R;31 double f1(double x){//(R*R - x*x)^(1/2)积分 32        return 0.5 * (x * sqrt(R*R - x*x) + R*R * asin(x / R)); 33 }34 35 double f2(double x){ //x^2*ln(x)积分 36        return x * x * x * (1.0/3 * log(x) - 1.0/9);37 }38 39 double f3(double x){ //x^2*ln(R + (R*R-x*x)^(1/2))积分 40        double s = sqrt(R*R-x*x); 41        return 1.0/18 * (-2*x*x*x-3*R*x*s + 3*R*R*R*atan(x/s) + 6*x*x*x*log(R + s));42 }43 44 double volume(double l){45       double r = R;46       double s1 = f1(r) - f1(l);47       double s2 = 0.5 * (f2(r) - f2(l));48       double s3 = 0.5 * R * (f1(r) - f1(l));49       double s4 = 0.5 * (f3(r) - f3(l));50       return H * s1 + (s2 - s3 - s4) * H / R;51 }52 53 void solve(){54       scanf("%lf%lf%lf", &H, &D, &V);55       R = D / 2;56       double l = 0, r = R, mid;57       for (int i = 0; i < 200; ++i){58             mid = (l + r) / 2;59             if (2 * volume(mid) < V) r = mid; 60             else l = mid;61       }62       printf("%.5f\n", l + R);63 }64 65 int main(){66 //    freopen("a.in", "r", stdin);67 //    freopen("a.out", "w", stdout);68     int cas = 0;69     scanf("%d", &cas);70     while (cas--){71          solve();72     }73     return 0;74 }
View Code

 

poj3929