Hdu 1071 - The area

初等高数,用定积分求面积

 

 

AC代码:

#include<stdio.h>
int main()
{
    int n,i;
    double x0,y0,x1,y1,x2,y2,k,b,a,c,h,s;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lf%lf%lf%lf%lf%lf",&x0,&y0,&x1,&y1,&x2,&y2);
        k=(y2-y1)/(x2-x1);
        b=y1-k*x1;
        h=x0;
        c=y0;
        a=(y1-c)/((x1-h)*(x1-h));
        s=(a*x2*x2*x2/3-(2*a*h+k)*x2*x2/2+(a*h*h+c-b)*x2)-(a*x1*x1*x1/3-(2*a*h+k)*x1*x1/2+(a*h*h+c-b)*x1);
        printf("%.2f\n",s);
    }
    return 0;
}


 

 

 


 

 

 

你可能感兴趣的:(Hdu 1071 - The area)