基本定积分求面积

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int T;
    double x1,x2,x3,y1,y2,y3,a,b,c;
    cin>>T;
    while(T--)
    {
        scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
        double k=(y3-y2)/(x3-x2);
        double h=y2-k*x2;
        if(k==0)
        {
            b=(2*y1)/x1;
            a=-b/(2*x1);
            c=0;
        }
        else
        {
            a=(y3-y2)/(x3*x3-x2*x2-2*x1*x3+2*x1*x2);
            b=-2*a*x1;
            c=y1-a*x1*x1-b*x1;
        }
        double i=(a*x3*x3*x3)/3.0+(b*x3*x3)/2.0+c*x3-(k*x3*x3)/2.0-h*x3;
        double j=(a*x2*x2*x2)/3.0+(b*x2*x2)/2.0+c*x2-(k*x2*x2)/2.0-h*x2;
        double s=i-j;
        printf("%.2lf\n",s);
    }
}

猜你喜欢

转载自www.cnblogs.com/Leozi/p/10835179.html