zoj 3832 Tilt Cylinder

zoj 3832 Tilt Cylinder


题意:一个与地面倾角为a的密封的圆柱体,内部有高度为h的水,问水的体积。


分析:(1)做与地面为a的倾角的面,其与水面的截面应为一个矩形。

           (2)设该面距离圆柱与地面的接触点的距离为x 则 0<x<min(2*r,h/cos(a))。

           (3) 截面矩形的宽为l1=2*sqrt(r*r-(r-x)*(r-x)),高为h1=min(H,(h/cos(a)-x)/tan(a)) 

           (4) v=(x)∑(l1*h1)

           (5) 数值积分



#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctype.h>
#include<algorithm>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define pi acos(-1.0)
#define MOD 1000000007
#define INF 0x3f3f3f3f
double r,H,h,aa,l;
double F(double x)
{
    double l1=sqrt(r*r-(x-r)*(x-r));
    double h1;
    if(fabs(aa)<1e-8) h1=H;
    else h1=min((l-x)/tan(aa),H);
    return l1*h1;
}

double simpson(double a,double b)
{
    double c=a+(b-a)/2;
    return (F(a)+4*F(c)+F(b))*(b-a)/6;
}

double asr(double a,double b,double eps,double A)
{
    double c=a+(b-a)/2;
    double L=simpson(a,c),R=simpson(c,b);
    if(fabs(L+R-A)<=15*eps) return L+R+(L+R-A)/15.0;
    return asr(a,c,eps/2,L)+asr(c,b,eps/2,R);
}

double asr(double a,double b,double eps){
    return asr(a,b,eps,simpson(a,b));
}

int main(void)
{
    while(scanf("%lf%lf%lf%lf",&r,&H,&h,&aa)!=EOF)
    {
        aa=aa/180*pi;
        if(fabs(aa-pi/2)<=1e-8)
        {
            printf("%.9f\n",pi*r*r*h);
            continue;
        }
        l=h/cos(aa);
        double x1=0;
        double x2=min(l,2*r);
        double ans=asr(x1,x2,1e-6);
        printf("%.9f\n",ans*2);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值