题意:
给你抛物线顶点,以及它与直线的两个交点,让我们来求直线和抛物线包围的面积的大小!
思路:
求出各个线的方程!!
求出k, h, a, b, c
y1 = kx + h; y2 = a*x*x + b * x + c;
再求出f (x) = (y1 - y2)的原积函数(x2 ~ x3)
area = F(x3) - F(x2).
代码:
#include
#include
#include
int main()
{
int t;
double x1, y1, x2, y2, x3, y3, k, h, a, b, c, area;
scanf("%d", &t);
while ( t-- )
{
scanf("%lf%lf", &x1, &y1);
scanf("%lf%lf", &x2, &y2);
scanf("%lf%lf", &x3, &y3);
k = (y3 - y2) / (x3 - x2);
h = y2 - k * x2;
a = (((y2 - y1) / (x2 - x1)) - ((y3 - y2) / (x3 - x2))) / (x1 - x3);
b = ((y2 - y1) / (x2 - x1)) - (a * (x1 + x2));
c = y3 - (a * x3 * x3 + b * x3);
area = ((a / 3)*x3*x3*x3 + ((b-k)/2)*x3*x3 + (c-h)*x3)
- ((a / 3)*x2*x2*x2 + ((b-k)/2)*x2*x2 + (c-h)*x2);
printf("%.2lf\n", area);
}
return 0;
}
第一次碰见纯数学问题。