您的位置:首页 > 其它

HDU 1071 The area

2012-10-09 14:15 246 查看


The area

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5149 Accepted Submission(s): 3597



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.



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

分析:就是已知3点,求抛物线和直线围成图形的面积,利用微积分公式求面积即可(已知抛物线的顶点,可以设抛物线为

y=a(x-b)^2+c较为简单)


代码:

#include<stdio.h>
#include<math.h>

struct node{
double x,y;
}p1,p2,p3;

int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y,&p3.x,&p3.y);
double x1=p1.x,x2=p2.x,x3=p3.x;//y=a(x-b)^2+c;
        double b=p1.x;
double c=p1.y;
double a=(p2.y-c)/((p2.x-b)*(p2.x-b));
double k=(p2.y-p3.y)/(p2.x-p3.x);
double d=p2.y-p2.x*k;
double s1=fabs((a/3*(x3-b)*(x3-b)*(x3-b)+c*x3)-(a/3*(x2-b)*(x2-b)*(x2-b)+c*x2));
double s2=fabs((k/2*x3*x3+d*x3)-(k/2*x2*x2+d*x2));
double s3=fabs(s1-s2);
printf("%.2lf\n",s3);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: