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 }

 

posted @ 2017-05-08 15:41  啦啦啦天啦噜  阅读(171)  评论(0编辑  收藏  举报