The area
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5917 Accepted Submission(s): 4130
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.
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).
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这个题的关键是解出抛物线方程中x的系数,即A、B、C,采用代入法代入抛物线方程的一般方程Ax^2+Bx+C=y后,有三个方程三个未知数,可以求出唯一的A、B、C,难点就是如何求出他们,这里要用到线性代数中用三阶行列式解三元方程的知识,求出系数以后,在x2到x3范围内积分即可。HintFor float may be not accurate enough, please use double instead of float.#include<stdio.h> int main() { double x1,x2,x3,y1,y2,y3,A,B,C,a,b,area,d,d1,d2,d3; int n; scanf("%d",&n); while(n--) { scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3); d=x1*x1*(x2-x3)+x2*x2*(x3-x1)+x3*x3*(x1-x2); //系数行列式 d1=y1*(x2-x3)+y2*(x3-x1)+y3*(x1-x2); //把A的系数换为y的行列式 d2=x1*x1*(y2-y3)+x2*x2*(y3-y1)+x3*x3*(y1-y2);//把B的系数换为y的行列式 d3=x1*x1*(x2*y3-x3*y2)+x2*x2*(x3*y1-x1*y3)+x3*x3*(x1*y2-x2*y1);//把C的系数换为y的行列式 A=d1/d; B=d2/d; C=d3/d; a=(y2-y3)/(x2-x3); //直线方程中x的系数 b=(y3-y2)*x2/(x2-x3)+y2; //直线方程中的常数项 area=(A*x3*x3*x3/3+(B-a)*x3*x3/2+(C-b)*x3)-(A*x2*x2*x2/3+(B-a)*x2*x2/2+(C-b)*x2); //在x2到x3范围内积分求面积 printf("%.2lf\n",area); } return 0; }