您的位置:首页 > 其它

hdu1071(积分求面积)

2013-05-16 21:57 337 查看
Problem Description
Ignatius bought a land last week, but he didn't know the area of the land because the land is enclosed by a parabola and a straight line. The picture below shows the area. Now given all the intersectant points shows in the picture,
can you tell Ignatius the area of the land?

Note: The point P1 in the picture is the vertex of the parabola.



Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.

Each test case contains three intersectant points which shows in the picture, they are given in the order of P1, P2, P3. Each point is described by two floating-point numbers X and Y(0.0<=X,Y<=1000.0).

Output
For each test case, you should output the area of the land, the result should be rounded to 2 decimal places.

Sample Input
2
5.000000 5.000000
0.000000 0.000000
10.000000 0.000000
10.000000 10.000000
1.000000 1.000000
14.000000 8.222222


Sample Output
33.33
40.69


#include<stdio.h>
#include<math.h>
struct pint
{
    double x,y;
}node;
int main()
{
    double a,m,c,k,b,area,f;
    struct pint p[4];
    int i,t;
    scanf("%d",&t);
    while(t--)
    {
        for(i=1;i<=3;i++)
        scanf("%lf%lf",&p[i].x,&p[i].y);

        k=(p[2].y-p[3].y)/(p[2].x-p[3].x);//直线方程为y=k*x+b;
        b=p[2].y-k*p[2].x;

                            //抛物线的方程为y=a*x^2+m*x+c;
        a=((p[2].x-p[3].x)*(p[1].y-p[2].y)-(p[1].x-p[2].x)*(p[2].y-p[3].y));
        a/=((p[1].x*p[1].x-p[2].x*p[2].x)*(p[2].x-p[3].x)-(p[2].x*p[2].x-p[3].x*p[3].x)*(p[1].x-p[2].x));
       m=(p[1].y-p[2].y)/(p[1].x-p[2].x)-a*(p[1].x+p[2].x);
       c=p[1].y-a* p[1].x*p[1].x-m*p[1].x;

       area=a/3*pow(p[3].x,3.0)+(m-k)/2*pow(p[3].x,2.0)+(c-b)*p[3].x;
      area-=(a/3*pow(p[2].x,3.0)+(m-k)/2*pow(p[2].x,2.0)+(c-b)*p[2].x);

     printf("%.2lf\n",area);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: