http://acm.hdu.edu.cn/showproblem.php?pid=1071
一条抛物线跟一条直线围成一个图形,给出两个交点和曲线最高点的坐标,求出面积,自己退出各个公式的系数,然后定积分求出结果
View Code
1 #include<stdio.h> 2 int main() 3 { 4 int t; 5 double x1,x2,x3,y1,y2,y3,a,b,c,k,h,s; 6 scanf("%d",&t); 7 while(t--) 8 { 9 scanf("%lf%lf",&x1,&y1); 10 scanf("%lf%lf",&x2,&y2); 11 scanf("%lf%lf",&x3,&y3); 12 k=(y3-y2)/(x3-x2); 13 h=y2-k*x2;//直线斜截式的斜率和截距 14 a=(((y2-y1)/(x2-x1))-((y3-y2)/(x3-x2)))/(x1-x3); 15 b=((y2-y1)/(x2-x1))-(a*(x1+x2)); 16 c=y3-(a*x3*x3+b*x3);//抛物线的a,b,c 17 s=((a/3)*x3*x3*x3+((b-k)/2)*x3*x3+(c-h)*x3)-((a/3)*x2*x2*x2+((b-k)/2)*x2*x2+(c-h)*x2);//定积分求面积 18 printf("%.2lf\n",s); 19 } 20 return 0; 21 }