一:数值积分

问题描述:求

仅说明    Simpon公式,以二次曲线逼近的方式取代矩形或者提醒面积,在EXP极小的情况下可以求得近似面积解

[图片源于他人BLOG]

long double simpson(long double l,long double r)
{
    long double mid=l+(r-l)/2.0;
    return (r-l)*(f(l)+4.0*f(mid)+f(r))/6.0;
}

例题:HDU1724

题意:求得L,R的积分解,套用simpson公式

BUG:为什么卡long double不得解,毕竟long double的精度不低于double?

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
#define debug puts
using namespace std;
typedef long long ll;

const int N=5e3+5;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;

double a,b,l,r,eps=1e-6;
double f(double t){
    return b*sqrt((1-t*t/a/a));
}

double simpson(double l,double r)
{
    double mid=l+(r-l)/2.0;
    return (r-l)*(f(l)+4.0*f(mid)+f(r))/6.0;
}

double solve(double l,double r,double eps){
    double mid=(l+r)/2;
    if(fabs(simpson(l,r)-simpson(l,mid)-simpson(mid,r))<eps)    return simpson(l,r);
    else    return solve(l,mid,eps/2)+solve(mid,r,eps/2);
}

int main(void){
    int t;
    cin>>t;
    while(t--){
        cin>>a>>b>>l>>r;
        printf("%.3f\n",2*solve(l,r,eps));
    }
    return 0;
}

例题:bzoj2178未完待续


二:高阶代数方程求根