zoukankan      html  css  js  c++  java
  • HUst 1360 Solve the integration(定积分模板)

    题意:

    就是给你一个函数,让你求他的定积分。

    //训练前不知道kuangbin dalao还有之中模板,真的是长见识了,差点爆零,还好有A题,不过A题也都是坑

    思路就是直接套模板

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cmath>
     4 double const eps=1e-6;
     5 
     6 double F(double x)
     7 {
     8     return 1.0/sqrt(1.0+x*x);
     9 }
    10 
    11 
    12 
    13 double simpson(double a,double b)
    14 {
    15     double c = a + (b-a)/2;
    16     return (F(a)+4*F(c) + F(b)) * (b-a)/6;
    17 }
    18 
    19 
    20 double asr(double a,double b,double eps,double A)
    21 {
    22     double c = a + (b-a)/2;
    23     double L = simpson(a,c),R = simpson(c,b);
    24     if(fabs(L + R - A) <= 15*eps)return L + R + (L + R - A)/15.0;
    25     return asr(a,c,eps/2,L) + asr(c,b,eps/2,R);
    26 }
    27 
    28 
    29 double asr(double a,double b,double eps)
    30 {
    31     return asr(a,b,eps,simpson(a,b));
    32 }
    33 
    34 int main()
    35 {
    36     double n;
    37     while(~scanf("%lf",&n))
    38     {
    39         printf("%.6f\n",asr(0,n,eps));
    40     }
    41     return 0;
    42 }
  • 相关阅读:
    Luogu P5853 [USACO19DEC]Tree Depth P
    Luogu P6009 [USACO20JAN]Non-Decreasing Subsequences P
    HDU6309 Absolute
    Luogu P4734 [BalticOI 2015]Hacker
    Gym102431F Ferry
    Gym102431G Game on the Tree
    AGC018F Two Trees
    Gym102268D Dates
    AGC023F 01 on Tree
    CF700E Cool Slogans
  • 原文地址:https://www.cnblogs.com/lalalatianlalu/p/6825351.html
Copyright © 2011-2022 走看看