[HDU1071]The area

题目:The area

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1071

分析:

 (1)推抛物线和直线的方程式,然后直接用微积分计算就好了。

 (2)看到一种很有趣的解法"抛物线弓形面积阿基米德算法",传送门:http://www.cnblogs.com/geloutingyu/p/5981409.html

代码:

#include <cstdio>
double a,b,c;
double f(double x){
    return a*x*x*x+b*x*x+c*x;
}
int main(){
    int Case;scanf("%d",&Case);
    double x1,x2,x3,y1,y2,y3,a1,a2,b1,b2,c1,c2;
    for(;Case--;){
        scanf("%lf%lf %lf%lf %lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
        a1=((y2-y1)/(x2-x1)-(y3-y2)/(x3-x2))/(x1-x3);
        b1=(y2-y1)/(x2-x1)-a1*(x2+x1);
        c1=y1-a1*x1*x1-b1*x1;
        a2=0;
        b2=(y3-y2)/(x3-x2);
        c2=y2-b2*x2;
        a=(a1-a2)/3;
        b=(b1-b2)/2;
        c=c1-c2;
        printf("%.2f\n",f(x3)-f(x2));
    }
    return 0;
}

 

posted @ 2017-04-03 22:03  hjj1871984569  阅读(218)  评论(0编辑  收藏  举报