hdoj 1071 The area 【简单数学题】

来源:互联网 发布:防闪退软件下载 编辑:程序博客网 时间:2024/04/30 14:51

题目大意: 给你三个点(p1是顶点, p2, p3在一条直线上, 三个点都在抛物线上), 求由直线与抛物线围成的面积

解题策略:只要是知道抛物线与直线的解析式的求法,外加一点积分,就求出来了,(什么,你不知道什么是积分,百度吧。。。)

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1071

AC by SWS

代码:

#include<stdio.h>#include<math.h>int main(){int t;double a, b, c1, c2, k, x1, y1, x2, y2, x3, y3;scanf("%d", &t);while(t --){scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);a = ((y1-y2)*(x2-x3)-(y2-y3)*(x1-x2))/((x1*x1-x2*x2)*(x2-x3)-(x2*x2-x3*x3)*(x1-x2));b = ((y1-y2)-a*(x1*x1-x2*x2))/(x1-x2);c1 = y1-a*x1*x1-b*x1;k = (y2-y3)/(x2-x3);c2 = y2- k*x2;double ans = (a/3)*(x2*x2*x2-x3*x3*x3)+(1.0/2)*(b-k)*(x2*x2-x3*x3)+(c1-c2)*(x2-x3);if(ans<0) ans = -ans;printf("%.2lf\n", ans);}return 0;}


 

 

0 0
原创粉丝点击