hdu 1071 辛普森方法

來源:互聯網
上載者:User
#include<cstdio>#include<cmath>double ah,h,ch,bb,cc,k,x1,x2,yy1,y2,x3,y3;// simpson公式用到的函數double F(double x) {  return (ah*(x-h)*(x-h)+ch-(k*(x-bb)+cc));}// 三點simpson法。這裡要求F是一個全域函數double simpson(double a, double b) {  double c = a + (b-a)/2;  return (F(a)+4*F(c)+F(b))*(b-a)/6;}// 自適應Simpson公式(遞迴過程)。已知整個區間[a,b]上的三點simpson值Adouble asr(double a, double b, double eps, double A) {  double c = a + (b-a)/2;  double L = simpson(a, c), R = simpson(c, b);  if(fabs(L+R-A) <= 15*eps) return L+R+(L+R-A)/15.0;  return asr(a, c, eps/2, L) + asr(c, b, eps/2, R);}// 自適應Simpson公式(主過程)double asr(double a, double b, double eps) {  return asr(a, b, eps, simpson(a, b));}double solve(){    h=x1;    ch=yy1;    ah=(y3-ch)/((x3-h)*(x3-h));    k=(y3-y2)/(x3-x2);    bb=x2;    cc=y2;    return asr(x2,x3,1e-6);}int main(){    int t;    scanf("%d",&t);    while(t--)    {        double ans;        scanf("%lf%lf",&x1,&yy1);        scanf("%lf%lf",&x2,&y2);        scanf("%lf%lf",&x3,&y3);        ans=solve();        printf("%.2lf\n",ans);  }  return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.