zoukankan      html  css  js  c++  java
  • 洛谷P4526 【模板】自适应辛普森法2(simpson积分)

    题目描述

    计算积分

    保留至小数点后5位。若积分发散,请输出"orz"。

    输入输出格式

    输入格式:

    一行,包含一个实数,为a的值

    输出格式:

    一行,积分值或orz

    输入输出样例

    输入样例#1: 复制
    2.33
    输出样例#1: 复制
    1.51068

    说明

    a<=50

    请注意时空限制。

    观察到函数具有极强的收敛性

    然后估算一下上界,直接上辛普森积分

    // luogu-judger-enable-o2
    #include<cstdio>
    #include<cmath>
    double a;
    double F(double x) {
        return pow(x, a / x - x);
    }
    double sim(double l, double r) {
        return (F(l) + F(r) + 4 * F((l + r) / 2)) * (r - l) / 6;
    }
    double asr(double L, double R, double eps, double ans) {
        double mid = (L + R) / 2;
        double LL = sim(L, mid), RR = sim(mid, R);
        if(fabs(LL + RR - ans) <= 15 * eps) return LL + RR;
        return asr(L, mid, eps / 2, sim(L, mid)) + asr(mid, R, eps / 2, sim(mid, R));
    }
    main() {
        #ifdef WIN32
        freopen("a.in", "r", stdin);
        #endif
        scanf("%lf", &a);
        if(a < 0) {printf("orz");return 0;}
        printf("%.5lf", asr(1e-9, 20, 1e-7, sim(0, 20)));
    } 
  • 相关阅读:
    制作dos启动u盘
    服务器之ECC报错检查
    shc 对 Linux shell 脚本加密.
    Linux
    windows查看端口占用
    python语言
    AppScan9.0安装破解
    局域网灰色设置解除
    shell脚本
    nginx安装
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/9148715.html
Copyright © 2011-2022 走看看