50Pts求调#辛普森
查看原帖
50Pts求调#辛普森
346410
_1009_楼主2024/1/29 11:34
#include<bits/stdc++.h>
#define f(i,l,r) for(int i=l;i<=r;i++)
#define F if
#define E else
using namespace std;
double a,b,c,d;
int read()
{
	int h=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
    {
    	F(ch=='-')
        	f=-1;
    	ch=getchar();
	}
	while(ch>='0'&&ch<='9')
    {
        h=h*10+ch-48;
        ch=getchar();
    }
	return h*f;
}
double fn(double x)
{
	return (c*x+d)/(a*x+b);
}
double sp(double l,double r)
{
	double c=(r+l)/2.0;
	return (r-l)*(fn(l)+4.0*fn(c)+fn(r))/6.0;
}
double asr(int l,int r)
{
	double m=(r+l)/2.0,Li,Ri,Mi;
	Li=sp(l,m);
	Ri=sp(m,r);
	Mi=sp(l,r);
	F(fabs(Li+Ri-Mi)<=1e-9)
		return Li+Ri;
	return asr(l,m)+asr(m,r);	
}
int main()
{
	double L,R,integral;
	/*a=read();
	b=read();
	c=read();
	d=read();
	L=read();
	R=read();*/
	cin>>a>>b>>c>>d>>L>>R;
	integral=sp(L,R);
	cout<<fixed<<setprecision(6)<<integral;
}
2024/1/29 11:34
加载中...