zoukankan      html  css  js  c++  java
  • luogu 自适应Simpson2

    自适应simpson2

    题意

    求一个不定积分

    解法

    画出函数的图像,可以知道其在0处函数值趋近于 $ + infty $,在10处趋近于0,所以我们从0积分到10就可以了(保险起见,积到15)

    代码如下:

    #include <iostream>
    #include <cstdio>
    #include <cctype>
    #include <cmath>
    using namespace std;
    typedef long long ll;
    template<typename T>
    inline void read(T&x)
    {
        x=0;T k=1;char c=getchar();
        while(!isdigit(c)){if(c=='-')k=-1;c=getchar();}
        while(isdigit(c)){x=x*10+c-'0';c=getchar();}x*=k;
    }
    const double eps=1e-7;
    double a;
    double F(double x){
        return pow(x,a/x-x);
    }
    double simpson(double a ,  double b){
        double mid=(a+b)/2;
        return  (F(a) + 4*F(mid) + F(b) ) * (b-a)/6 ;
    }
    double asr(double a,double b,double e,double A){
        double mid = (a+b)/2;
        double L = simpson(a,mid) , R = simpson(mid,b);
        if(fabs(L+R-A) <= 15*eps ) return L+R+(L+R-A)/15.0;
        return asr(a,mid,e/2,L) + asr(mid,b,e/2,R);
    }
    double asr(double l,double r) {
        return asr(l,r,eps,simpson(l,r));
    }
    
    int main()
    {
        scanf("%lf",&a);
        if(a<0) printf("orz");
        else printf("%.5lf",asr(eps,15.0)); 
        return 0;
    }
    
  • 相关阅读:
    pycharm 快捷键
    jquery .on
    javaweb项目的优化
    python笔记
    git上解决代码冲突(merge版)
    OpenERP里面继承的用法
    OpenERP新手易犯错误之res.model
    bootstrap 仿实例
    深入理解Binder(二),Binder是什么?
    深入理解Binder(一),从AIDL谈起
  • 原文地址:https://www.cnblogs.com/mrasd/p/9520011.html
Copyright © 2011-2022 走看看