zoukankan      html  css  js  c++  java
  • HDU 1724 Ellipse 自适应simpson积分

    simpson公式是用于积分求解的比较简单的方法(有模板都简单……

    下面是simpson公式(很明显 这个公式的证明我并不会……

    (盗图……

    因为一段函数基本不可能很规则 所以我们要用自适应积分的方法

    找了一道很水的积分题试试模板……

    关于simpson要*15 网上有很具体的证明过程……

    int_{a}^b f(x) mathrm{d}x = S(a, c) + S(c, b) + frac{1}{15}[S(a, c) + S(b, c) - S(a, b)] + O((b - a)^6)

    (细节移步至:http://www2.math.umd.edu/~mariakc/teaching/adaptive.pdf

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cmath>
     5 #include<cstring>
     6 #include<string>
     7 #define cl(a,b) memset(a,b,sizeof(a))
     8 #define debug(x) cerr<<#x<<"=="<<(x)<<endl
     9 using namespace std;
    10 typedef long long ll;
    11 const double eps=1e-6;
    12 
    13 double a,b,l,r;
    14 
    15 double f(double x)
    16 {//原函数
    17     return sqrt((b*b)*(1-(x*x)/(a*a)));
    18 }
    19 
    20 double simpson(double a,double b)
    21 {//simpson公式
    22     double c=a+(b-a)/2;
    23     return (f(a)+4*f(c)+f(b))*(b-a)/6;
    24 }
    25 
    26 double asr(double a,double b,double eps,double A)
    27 {//自适应部分
    28     double c=a+(b-a)/2;
    29     double L=simpson(a,c);
    30     double R=simpson(c,b);
    31     if(fabs(L+R-A)<=15*eps) return L+R+(L+R-A)/15.0;//判断是否满足精度
    32     return asr(a,c,eps/2,L)+asr(c,b,eps/2,R);
    33 }
    34 
    35 double asr(double a,double b,double eps)
    36 {//积分
    37     return asr(a,b,eps,simpson(a,b));
    38 }
    39 
    40 int main()
    41 {
    42     int T;
    43     scanf("%d",&T);
    44     while(T--)
    45     {
    46         scanf("%lf%lf%lf%lf",&a,&b,&l,&r);
    47         printf("%.3f
    ",2*asr(l,r,eps));
    48     }
    49     return 0;
    50 }
    51 /*
    52 
    53 2
    54 2 1 -2 2
    55 2 1 0 2
    56 
    57 */

    当然上面是数学不好的同学做的

    数学好的同学是这么做的……

     1 #include<cstdio>
     2 #include<cmath>
     3 int main()
     4 {
     5     int T;
     6     scanf("%d",&T);
     7     while(T--)
     8     {
     9         double a,b,l,r;
    10         scanf("%lf%lf%lf%lf",&a,&b,&l,&r);
    11         double ans=acos(l/a);
    12         double ant=acos(r/a);
    13         double re=a*b*((sin(2*ant)-sin(2*ans))/2-(ant-ans));
    14         printf("%.3f
    ",re);
    15     }
    16     return 0;
    17 }

    (毫无疑问 这个同学不是我……

  • 相关阅读:
    js笔记一:在HTML中使用javascript
    opencv排错总结
    《学习openCV》例程解析 ex_8_2 (轮廓)
    《学习openCV》例程解析 ex_9_3(codeBook模型实现背景减除)
    《学习openCV》例程解析 ex_9_1 (像素片段)
    《学习openCV》例程解析 ex_9_2(背景减除)
    《学习openCV》例程解析 ex_8_3 (轮廓)
    JavaScript鼠标事件
    sumlime text2 快捷键
    HTML字符实体(转)
  • 原文地址:https://www.cnblogs.com/general10/p/6270957.html
Copyright © 2011-2022 走看看