题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1071
定积分求面积,关键是求出抛物线和直线的方程。。
#include <iostream>
using namespace std;
int main()
{
// y = kx + m, y = a x^2 + bx + c;
double area, k, m, a, b, c;
double x1, y1, x2, y2, x3, y3;
int t;
cout.setf(ios::fixed);
cout.precision(2);
while (cin >> t) {
while (t--) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
k = (y3 - y2) / (x3 - x2);
m = y2 - k * x2;
a = (y2 - y1) / (x2 - x1) / (x2 - x1);
b = -2 * a * x1;
c = a * x1 * x1 + y1;
area = (a / 3) * (x3 * x3 * x3 - x2 * x2 * x2) +
(b - k) / 2 * (x3 * x3 - x2 * x2) +
(c - m) * (x3 - x2);
cout << area << endl;
}
}
return 0;
}