The area 积分积分

The area

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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.

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
 
 
 #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
struct point
{
double x,y;
} p1,p2,p3;
double a,b,c,a1,b1;
double F(double x)
{
return fabs(a*(x-b)*(x-b)+c-a1*x-b1);
}
void init()
{
b = p1.x;
c = p1.y;
a = (p2.y - c) / (p2.x - b) / (p2.x - b);
a1 = (p3.y - p2.y) / (p3.x - p2.x);
b1 = p2.y - a1 * p2.x;
//cout<<a<<" "<<b<<" "<<c<<" "<<a1<<" "<<b1<<" "<<endl;
}
//三点辛普森公式
double simpson(double width,double fa,double fb,double fc)
{
return (fb+fa+*fc)*width/;
} //自适应simpson公式递归过程
double asr(double a,double b,double eps,double A)
{
double c=(a+b)/;
double fa,fb,fc,L,R;
fa=F(a);
fb=F(b);
fc=F(c);
L=simpson(c-a,fa,fc,F((c+a)/));
R=simpson(b-c,fc,fb,F((b+c)/));
if(fabs(L+R-A)<=*eps) return L+R+(L+R-A)/;
return asr(a,c,eps/,L)+asr(c,b,eps/,R);
}
double asr1(double a,double b,double eps)
{
return asr(a,b,eps,simpson(b-a,F(a),F(b),F((b+a)/)));
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf",&p1.x,&p1.y);
scanf("%lf%lf",&p2.x,&p2.y);
scanf("%lf%lf",&p3.x,&p3.y);
init();
printf("%.2lf\n",asr1(p2.x,p3.x,0.0000001));
}
}
 
 
上一篇:201521123106 《Java程序设计》第6周学习总结


下一篇:MUI(1)