HDU_1071——积分求面积,抛物线顶点公式

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.HDU_1071——积分求面积,抛物线顶点公式
 
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
 /*
看图直接能看出来这是X-区域,X-区域的积分公式是
b Q2(x)
∫ dx∫ 1*dy
a Q1(x)
先对y积分,然后对y积分,y的积分上下限是两个函数
/*
由图可知
a=x2
b=x3
Q1(x)=过p1,p2两点的直线方程
Q2(x)=抛物线方程
*/
/*
我尼玛把抛物线顶点公式给忘了- -白活了
顶点 (h,b) 抛物线 y=a(x-h)^2+b
所以Q2(x)=((y2-y1)/(x2-x1)^2)*(x-x1)^2+y1
Q1(x)=(y3-y2)/(x3-x2)*x+y2-(y3-y2)/(x3-x2)*x2
*/
#include <cstdio>
int main()
{
int n;
double x1,y1,x2,y2,x3,y3;
scanf("%d",&n);
while(n--)
{
scanf("%lf%lf",&x1,&y1);
scanf("%lf%lf",&x2,&y2);
scanf("%lf%lf",&x3,&y3);
double a=(y2-y1)/((x2-x1)*(x2-x1));
double b=-*a*x1;
double c=a*x1*x1+y1; //这个数据浪费了我40分钟,艹
double k=(y3-y2)/(x3-x2);
double t=y2-k*x2;
// x3
// s=∫ Q2(x)-Q1(x) dx
// x2
double s=a/*(x3*x3*x3-x2*x2*x2)+(c-t)*(x3-x2)+0.5*(b-k)*(x3*x3-x2*x2);
printf("%.2lf\n",s);
}
return ;
}
上一篇:QQ情侣头像~


下一篇:运维自动化之SALTSTACK简单入门