The area
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
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.
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).
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.69HintFor float may be not accurate enough, please use double instead of float.
Author
Ignatius.L
题意:该题给你三个点P1(P1抛物线的顶点),P2,P3(P2,P3为直线与抛物线的交点),让你求抛物线与直线围成区域的面积
抛物线与直线,已知两交点P2(x2,y2),P3(x3,y3),可以求出k的值和b的值
由于P1(x1,y1)是抛物线的顶点,所以
再根据P1,P2两点可以求出a,b,c
最后再用积分求出面积的表达式即可
剩下的便是纯代公式,附上代码
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stdlib.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 50005;
const int inf = 1000000000;
const int mod = 1000000007;
int main()
{
int t;
double x1,y1,x2,y2,x3,y3,a,b,c,d,k;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
k=(y3-y2)/(x3-x2);
d=y2-k*x2;
a=(y2-y1)/((x2-x1)*(x2-x1));
b=-2*a*x1;
c=y2-a*x2*x2-b*x2;
printf("%.2f\n",a*(x3*x3*x3-x2*x2*x2)/3+(b-k)*(x3*x3-x2*x2)/2+(c-d)*(x3-x2));
}
return 0;
}
菜鸟成长记