HDU 1071 The area(求三个点确定的抛物线的面积,其中一个点是顶点)

时间:2023-01-10 13:19:05

传送门:

http://acm.hdu.edu.cn/showproblem.php?pid=1071

The area

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12095    Accepted Submission(s): 8490

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  The area(求三个点确定的抛物线的面积,其中一个点是顶点)

 
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
Hint

For float may be not accurate enough, please use double instead of float.

 
Author
Ignatius.L
 
题目意思:
告诉你三个点,有一个点抛物线顶点,问你这三个点在抛物线中确定的面积
 
分析:
设抛物线y=a(x-b)^2+c   p1总是抛物线的顶点
    所以根据p1和另外随便一个点我们可以确定抛物线方程中的所有参数
    直线方程y=kx+d;
    抛物线方程减去直线方程的积分就是二者形成的面积
    面积就是a(x-b)^2+c-kx-d的积分
 
code:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
double a,b,c,k,d;
double f(double x)//积分
{
return a*x*x*x/-(*a*b+k)*x*x/+(a*b*b+c-d)*x;
}
int main()
{
/*
设抛物线y=a(x-b)^2+c p1总是抛物线的顶点
直线方程y=kx+d;
面积就是a(x-b)^2+c-kx-d的积分
*/
double x1,y1,x2,y2,x3,y3;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
c=y1;
b=x1;
a=(y2-c)/((x2-b)*(x2-b));
k=(y3-y2)/((x3-x2));
d=y2-k*x2;
printf("%0.2lf\n",f(x3)-f(x2));
}
return ;
}