`
444878909
  • 浏览: 635958 次
文章分类
社区版块
存档分类
最新评论

HDU 2493 Timer 数学(二分+积分)

 
阅读更多

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2493


题意:给你一个圆锥,水平放置,圆锥中心轴与地面平行,将圆锥装满水,在圆锥某一表面开一个小洞,流出来水的体积为V,给你地面直径D,高H,让你求小洞里地面的距离。(保证距离大于等于半径,小于等于直径)

题解:因为流出来水的那部分是一个不规则形状(相当于将圆锥水平切开,截面是一个三角形),我们可以二分答案下降高度r,现在关键是求体积。


然后通过一系列很复杂的积分运算,得出结果:


记得最后求出来的答案要用直径减去。


AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std;

#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define sd1(a) scanf("%lf",&a)
#define sd2(a,b) scanf("%lf%lf",&a,&b)
#define ss1(s)  scanf("%s",s)
#define pi1(a)    printf("%d\n",a)
#define pi2(a,b)  printf("%d %d\n",a,b)
#define mset(a,b)   memset(a,b,sizeof(a))
#define forb(i,a,b)   for(int i=a;i<b;i++)
#define ford(i,a,b)   for(int i=a;i<=b;i++)

typedef long long LL;
const int N=100005;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-8;

double H,D,V,R;

double xiaohao(double r)//这个地方求积分很麻烦,我就只写结果了
{
    double xh=0;
    xh+=H*R*R*acos((R-r)/R)/3.0;
    xh-=2.0/3.0*(R-r)*H*sqrt(R*R-(R-r)*(R-r));
    xh+=1.0/3.0*(R-r)*(R-r)*(R-r)*H/R*log((R+sqrt(R*R-(R-r)*(R-r)))/(R-r));
    return xh;
}

int main()
{
//    freopen("input.txt","r",stdin);
    int i,j,T;
    si1(T);
    while(T--)
    {
        sd1(H);sd2(D,V);
        R=D/2;
        double low=0,up=R,m,tmp;
        while((up-low)>eps)//二分高度
        {
            m=(up+low)/2;
            double tmp=xiaohao(m);//求出体积,和V比较
            if(tmp>V)
                up=m;
            else
                low=m;
        }
        printf("%.5f\n",D-m);
    }
    return 0;
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics