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.
![](https://i-blog.csdnimg.cn/blog_migrate/91dc24a066eaa3cddad6393bc62ad561.png)
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 看不懂没关系,题目要求就是给定三个点求定积分。不要怀疑,这就是一道数学题。算法由小宁友情提供;3个根(x1,y1)(x2,y2)(x3,y3) 方程ax^2+bx+c=0 求解: -b/2a=x1;(4ac-b^2)/4a=y1;两式联立c-ax1^2=y1;b=-2ax1 再利用(x2,y2) ax2^2+bx2+c=y2;代入c,b a(x2^2-2x1x2+x1^2)=y2-y1 所以:a=(y2-y1)/((x2-x1)^2); 所以b,c可以解出#include<stdio.h> int main() { int n; double x1,x2,x3,y1,y2,y3,k,m,a,b,c,s; //float不够 scanf("%d",&n); while(n--) { scanf("%lf%lf",&x1,&y1);//输入 scanf("%lf%lf",&x2,&y2); scanf("%lf%lf",&x3,&y3); k=(y3-y2)/(x3-x2);//直线斜率 m=y3-k*x3;//截距(好像是这个名吧==忘了) a=(y2-y1)/(x2-x1)/(x2-x1);//抛物线的a,b,c b=(-2)*a*x1; c=a*x1*x1+y1; s=(1/3.0)*a*x3*x3*x3+0.5*b*x3*x3+c*x3-0.5*k*x3*x3-m*x3-((1/3.0)*a*x2*x2*x2+0.5*b*x2*x2+c*x2-0.5*k*x2*x2-m*x2); if(s<0)//我记得积分好像能求出负的来 s=-s; printf("%.2lf\n",s);//保留两位小数 } return 0; }