一:杭电原题摘录
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=1&problemid=10
二.题目分析
题目大意是输入以上图形的三个点p1,p2,p3坐标,计算两条曲线所围成的面积.属于计算几何学.
很明显面积等于曲面面积-梯形面积,但由于抛物线的开口方向不确定,像下图所示,那就是梯形面积-曲面面积,所以应该取绝对值
梯形面积很容易求.曲面面积需要用定积分去求.由二次函数定点式知f(x)=A+P1.y
那么,F(x)=+P1.y.
三.我的收获
第一次编程求积分.遇到没见过的类型,用自己学过的知识一步一步去做,就能慢慢找到答案.
四.AC代码
#include <iostream>
#include <math.h>
using namespace std;
namespace {
struct Point
{
double x, y;
};
}
int main()
{
int T;
cin >> T;
while (T--)
{
Point P1, P2, P3;
cin >> P1.x >> P1.y >> P2.x >> P2.y >> P3.x >> P3.y;
double TrapezoidArea = (P2.y + P3.y) * (P3.x - P2.x) / 2;
double a = (P2.y - P1.y) / (P2.x - P1.x) / (P2.x - P1.x);
double b = P1.x;
double c = P1.y;
double CurveArea = (a / 3 * pow(P3.x - b, 3) + c * P3.x) - (a / 3 * pow(P2.x - b, 3) + c * P2.x);
printf("%.2lf\n", abs(CurveArea - TrapezoidArea));//绝对值
}
return 0;
}