hdu1071(抛物线,直线以及二重积分)

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

View Code
// 抛物线 yp=a*(x-b)^2+c;
// 直线 yz=k*x+s;
// 二重积分公式: f(x0,x1)(yp-yz)*dx;

#include
" iostream "
using namespace std;
double a,b,c,k,s;
double fun( double x)
{
return 1.0 * (a * x * x * x / 3 ) - 1.0 * (a * b + k / 2 ) * x * x + (a * b * b + c - s) * x;
}
int main()
{
int t;
double x1,y1,x2,y2,x3,y3;
scanf(
" %d " , & t);
while (t -- )
{
scanf(
" %lf%lf%lf%lf%lf%lf " , & x1, & y1, & x2, & y2, & x3, & y3);

k
= (y3 - y2) / (x3 - x2);
s
= y3 - k * x3;

a
= (y2 - y1) / ((x2 - x1) * (x2 - x1));
b
= x1;
c
= y1;

double area = 1.0 * (fun(x3) - fun(x2));
printf(
" %.2lf\n " ,area);
}
return 0 ;
}

你可能感兴趣的:(HDU)