HDU 1071 The area 详解

来源:互联网 发布:网络有前景的项目 编辑:程序博客网 时间:2024/06/14 12:27

The area


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
25.000000 5.0000000.000000 0.00000010.000000 0.00000010.000000 10.0000001.000000 1.00000014.000000 8.222222
Sample Output
33.3340.69          
Hint
For float may be not accurate enough, please use double instead of float.
详细题解:
这道题是一道数学水题。解决这道题的方法可以是求定积分的方法。而用定积分的方法,需要知道抛物线的方程表示和直线的方程表示;利用这两方程的表示进行定积分计算即可求出所要求得面积。。
由样例可知点坐标和面积的数据类型需要采用double型。输入P1,P2,P3的坐标(x0,y0),(x1,y1),(x2,y2);设直线的方程为kx+B=0,由P2,P3点可知 k=(y2-y1)/(x2-x2);B=y1-k*x1;设抛物线的方程为ax^2+bx+c=0,由P0,P1可知 a=(y1-y0)/((x1-x0)^2);可知抛物线的顶点坐标表示为(-b/(2*a),((4*a*c)-b^2)/4*a),即由P1(x0,y0)可知b=-2*a*x0,,c=a*x0^2+y0;所以所求面积S为 ax^2+bx+c-(kx+B)在下限为x1,上限为x2的情况下的定积分。
下面附上AC代码:
#include<stdio.h>int main(){int t,i;double x0,y0,x1,y1,x2,y2,k,b,a,s,m,n;while(~scanf("%d",&t)){for(i=0;i<t;i++){scanf("%lf%lf%lf%lf%lf%lf",&x0,&y0,&x1,&y1,&x2,&y2);k=(y2-y1)/(x2-x1);        b=y1-k*x1;        m=x0;        n=y0;        a=(y1-n)/((x1-m)*(x1-m));        s=(a*x2*x2*x2/3-(2*a*m+k)*x2*x2/2+(a*m*m+n-b)*x2)-(a*x1*x1*x1/3-(2*a*m+k)*x1*x1/2+(a*m*m+n-b)*x1);        printf("%.2f\n",s);}}return 0;}

原创粉丝点击