hdu 1071

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

题意:按图,给出p1,p2,p3的坐标,计算阴影部分面积。

mark:就是求公式咯。设y = ax^2 + bx + c。用(x1,y1),(x2,y2)相减再联合顶点坐标(-b/2a, c-b^2/4a)可以轻易求出a,b,c的值。之后算积分就可以了。注意还要减去直线和x轴所夹梯形的面积。

代码:

 1 # include <stdio.h>
 2 # include <math.h>
 3 
 4 
 5 double fun(double a, double b, double c, double x)
 6 {
 7     return a*x*x*x / 3 + b*x*x/2 + c*x ;
 8 }
 9 
10 
11 int main ()
12 {
13     int T, i ;
14     double x[4], y[4] ;
15     double a, b, c, area ;
16     scanf ("%d", &T) ;
17     while (T--)
18     {
19         for (i = 1 ; i <= 3 ; i++)
20             scanf ("%lf%lf", &x[i], &y[i]) ;
21         a = (y[2]-y[1])/((x[2]-x[1])*(x[2]+x[1]-2*x[1])) ;
22         b = -2*a*x[1] ;
23         c = y[1] + b*b/(4*a) ;
24         area = fabs(fun(a,b,c,x[3]) - fun(a,b,c,x[2])) ;
25         area -= fabs((y[2]+y[3])*(x[3]-x[2])*0.5) ;
26         printf ("%.2lf\n", area) ;
27     }
28     return 0 ;
29 }
原文地址:https://www.cnblogs.com/lzsz1212/p/2441676.html