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 a random point on the parabola, and P2, P3 are the intersectant points. Any two points of P1, P2 and P3 are not coincidence each other.
![](https://i-blog.csdnimg.cn/blog_migrate/998dfc9214421eeb8a10bb72a6f5f0fd.bmp)
输入
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).
输出
For each test case, you should output the area of the land, the result should be rounded to 2 decimal places.
样例输入
样例输出
题目大意: 给出抛物线顶掉p1的坐标及与直线的交点p2和p3的坐标,求相交部分的面积。
直线p2,p3的方程设为y=kx+b;-->k=(y3-y2)/(x3-x2);
又p2点在直线上,所以y2=k*x2+b,--->b=y2-k*x2;
然后微分,区间为(x2,x3),方程化简可得以下式子。
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; int main() { int t; double x1,y1,x2,y2,x3,y3; cin>>t; while(t--) { scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3); double a=(y2-y1)/((x2-x1)*(x2-x1)); double k=(y3-y2)/(x3-x2); double b=y2-k*x2; double c=x3-x2; double d=x3*x3-x2*x2; double ans; ans=a*(x3*x3*x3-x2*x2*x2)/3-a*x1*d+a*x1*x1*c+y1*c-k*d/2-b*c; printf("%.2lf\n",ans); } return 0; }