hdu 1071 The area

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

 又是纯数学题,设y=ax^2+bx+c,y=kx+h,利用p1,p2,p3

解出:a=(y2-y1)/((x2-x1)*(x2-x1));
    b=-2*a*x1;
    c=y1-a*x1*x1-b*x1;
    k=(y2-y3)/(x2-x3);
    h=y2-k*x2;

#include<iostream>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include<queue>
#include<list>
#include<set>
#include<string.h>
#include<stdlib.h>
//#include<math.h>
#include<stdio.h>
#include<ctype.h>
#include<iomanip>
using namespace std;

#define LL long long
#define pi acos(-1)
double x1,y1,x2,y2,x3,y3,a,b,c,k,h;
double cal(double x)
{
    return a*x*x*x/3.0+(b-k)*x*x/2.0+(c-h)*x;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
    scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
    a=(y2-y1)/((x2-x1)*(x2-x1));
    b=-2*a*x1;
    c=y1-a*x1*x1-b*x1;
    k=(y2-y3)/(x2-x3);
    h=y2-k*x2;
    double ans=cal(x3)-cal(x2);
    printf("%.2f\n",ans);
    }
    return 0;

}

你可能感兴趣的:(hdu 1071 The area)