zoukankan      html  css  js  c++  java
  • 自适应Simpson公式

    参考刘汝佳<算法指南>P163

    #include<cstdio>
    #include<cmath>
    double a;
    double F(double x){
        return sqrt(1+4*a*a*x*x);
    }
    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));
    }
    double parabola_arc_length(double w,double h)
    {
        a=4.0*h/(w*w);
        return ASR(0,w/2,1e-5)*2;
    }
    int main()
    {
        int T;
        scanf("%d",&T);
        for(int cas=1;cas<=T;cas++){
            int D,H,B,L;
            scanf("%d%d%d%d",&D,&H,&B,&L);
            int n=(B+D-1)/D;
            double D1=(double)B/n;
            double L1=(double)L/n;
            double x=0,y=H;
            while(y-x>1e-5){
                double m=x+(y-x)/2;
                if(parabola_arc_length(D1,m)<L1) x=m;
                else y=m;
            }
            if(cas>1) printf("
    ");
            printf("Case %d:
    %.2lf
    ",cas,H-x);
        }    
    }
  • 相关阅读:
    Post返回json值
    调用接口并获取放回json值
    c# 获取IP
    sqlserver2008不允许保存更改
    判断客户端是否是手机或者PC
    3.docker tomcat集群
    1.docker 安装
    Maven profiles 多环境配置
    MySQL 定时任务
    MyBatis 三剑客
  • 原文地址:https://www.cnblogs.com/freinds/p/6406291.html
Copyright © 2011-2022 走看看