The area

特别简单的题
随便搞搞就能过吧,根据抛物线顶点和另外一个点,就可以求出抛物线的方程,然后再用一般式求出直线方程
函数就是抛物线减去直线,区间就是([p_2.x,p_3.x]),然后自适应辛普森积分积分一下就行了
抛物线方程(y = Ax^2 + Bx + C),直线方程(y = Kx + b)

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double eps = 1e-9;
struct Point{
    double x, y;
}p[4];
double A, B, C, K, b;
double f(double x){// 函数
    return A * x * x + x * (B - K) + C - b;
}
double simpson(double l, double r){ // simpson公式
    double mid = l + (r - l) / 2;
    return (r - l) * (f(l) + 4 * f(mid) + f(r)) / 6;
}
double asr(double l, double r, double ans){ // 拟合
    double mid = l + (r - l) / 2;
    double ans1 = simpson(l, mid), ans2 = simpson(mid, r);
    if(fabs(ans1 + ans2 - ans) <= eps) return ans;
    return asr(l, mid, ans1) + asr(mid, r, ans2);
}
void solve(){
    for(int i = 1; i <= 3; i++)
        cin >> p[i].x >> p[i].y;
    A = (p[2].y - p[1].y) / (p[2].x - p[1].x) / (p[2].x - p[1].x);
    B = -2 * A * p[1].x;
    C = p[1].y - A * p[1].x * p[1].x - B * p[1].x;
    K = (p[3].y - p[2].y) / (p[3].x - p[2].x);
    b = p[3].y - K * p[3].x;

    printf("%.2lf
", asr(p[2].x, p[3].x, simpson(p[2].x, p[3].x)));
}
int main(){
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}
原文地址:https://www.cnblogs.com/Emcikem/p/13328335.html