题意:

poj3929-LMLPHP

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

思路:

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

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

code:

 /*
* Author: Yzcstc
* Created Time: 2014/10/2 13:59:16
* File Name: poj3929.cpp
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<ctime>
#define repf(i, a, b) for (int i = (a); i <= (b); ++i)
#define repd(i, a, b) for (int i = (a); i >= (b); --i)
#define M0(x) memset(x, 0, sizeof(x))
#define Inf 0x7fffffff
#define MP make_pair
#define PB push_back
#define eps 1e-8
#define pi acos(-1.0)
typedef long long LL;
using namespace std;
double H, D, V;
double R;
double f1(double x){//(R*R - x*x)^(1/2)积分
return 0.5 * (x * sqrt(R*R - x*x) + R*R * asin(x / R));
} double f2(double x){ //x^2*ln(x)积分
return x * x * x * (1.0/ * log(x) - 1.0/);
} double f3(double x){ //x^2*ln(R + (R*R-x*x)^(1/2))积分
double s = sqrt(R*R-x*x);
return 1.0/ * (-*x*x*x-*R*x*s + *R*R*R*atan(x/s) + *x*x*x*log(R + s));
} double volume(double l){
double r = R;
double s1 = f1(r) - f1(l);
double s2 = 0.5 * (f2(r) - f2(l));
double s3 = 0.5 * R * (f1(r) - f1(l));
double s4 = 0.5 * (f3(r) - f3(l));
return H * s1 + (s2 - s3 - s4) * H / R;
} void solve(){
scanf("%lf%lf%lf", &H, &D, &V);
R = D / ;
double l = , r = R, mid;
for (int i = ; i < ; ++i){
mid = (l + r) / ;
if ( * volume(mid) < V) r = mid;
else l = mid;
}
printf("%.5f\n", l + R);
} int main(){
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
int cas = ;
scanf("%d", &cas);
while (cas--){
solve();
}
return ;
}
05-11 22:36