hdu 1724数学题 辛普森公式求积分
2014-09-16 23:06
453 查看
Problem Description
Math is important!! Many students failed in 2+2’s mathematical test, so let's AC this problem to mourn for our lost youth..
Look this sample picture:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202003/21/655ca3325cc7eefbc2d4c50d715e5657.jpg)
A ellipses in the plane and center in point O. the L,R lines will be vertical through the X-axis. The problem is calculating the blue intersection area. But calculating the intersection area is dull, so I have turn to you, a talent of programmer. Your task
is tell me the result of calculations.(defined PI=3.14159265 , The area of an ellipse A=PI*a*b )
就是求阴影部分面积,用辛普森公式求积分, 求f(x)*dx在区间 [l,r]上的积分。#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
double a1,b1;
double F(double x){ //函数f[x]
return b1/a1*sqrt(a1*a1-x*x);
}
double simpson(double a,double b)
{
double c=a+(b-a)/2;
return (F(a)+4*F(c)+F(b))*(b-a)/6;
}
double 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);
}
double asr(double a,double b,double eps){
return asr(a,b,eps,simpson(a,b));
}
double parabola_arc_length(double l,double r){ // 区间[l,r]
return asr(l,r,1e-5)*2;
}
int main()
{
double l,r;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf%lf",&a1,&b1,&l,&r);
printf("%.3lf\n",parabola_arc_length(l,r));
}
return 0;
}
Math is important!! Many students failed in 2+2’s mathematical test, so let's AC this problem to mourn for our lost youth..
Look this sample picture:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202003/21/655ca3325cc7eefbc2d4c50d715e5657.jpg)
A ellipses in the plane and center in point O. the L,R lines will be vertical through the X-axis. The problem is calculating the blue intersection area. But calculating the intersection area is dull, so I have turn to you, a talent of programmer. Your task
is tell me the result of calculations.(defined PI=3.14159265 , The area of an ellipse A=PI*a*b )
就是求阴影部分面积,用辛普森公式求积分, 求f(x)*dx在区间 [l,r]上的积分。#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
double a1,b1;
double F(double x){ //函数f[x]
return b1/a1*sqrt(a1*a1-x*x);
}
double simpson(double a,double b)
{
double c=a+(b-a)/2;
return (F(a)+4*F(c)+F(b))*(b-a)/6;
}
double 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);
}
double asr(double a,double b,double eps){
return asr(a,b,eps,simpson(a,b));
}
double parabola_arc_length(double l,double r){ // 区间[l,r]
return asr(l,r,1e-5)*2;
}
int main()
{
double l,r;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf%lf",&a1,&b1,&l,&r);
printf("%.3lf\n",parabola_arc_length(l,r));
}
return 0;
}
相关文章推荐
- hdu 1724 辛普森公式求积分
- HDU 1724 Ellipse(数值积分の辛普森公式)
- HDU-4969 Just a Joke (数学 - 积分)
- hdu 1724 Ellipse (自适应辛普森求积分 模板题)
- HDU 1724 Ellipse (simpson公式,求积分)
- hdu 1724 Ellipse(自适应Simpson积分) (模板)
- HDU 1724 Ellipse 自适应辛普森积分
- HDU 1724 Ellipse (自适应辛普森公式)
- HDU 1724 Ellipse (自适应辛普森积分模板题)
- hdu 1724 Ellipse(自适应Simpson积分) (模板)
- HDU 1724: Ellipse simpson积分
- HDU 1724 Ellipse 【自适应Simpson积分】
- HDU 1724 辛普森积分公式
- hdu 1724 Ellipse(自适应Simpson积分) (模板)
- HDU 1724 Ellipse 【自适应Simpson积分】
- hdu 1724 辛普森积分
- HDU 2493 Timer 数学(二分+积分)
- HDU多赛学校9 HDU4969 Just a Joke 【数学积分】
- HDU 5826 数学积分
- hdu 1724 Ellipse(自适应Simpson积分) (模板)