HDU 1071 The area 详解
来源:互联网 发布:网络有前景的项目 编辑:程序博客网 时间:2024/06/14 12:27
The area
Ignatius bought a land last week, but he didn't know the area of the land because the land is enclosed by a parabola and a straight line. The picture below shows the area. Now given all the intersectant points shows in the picture, can you tell Ignatius the area of the land?
Note: The point P1 in the picture is the vertex of the parabola.
Note: The point P1 in the picture is the vertex of the parabola.
Each test case contains three intersectant points which shows in the picture, they are given in the order of P1, P2, P3. Each point is described by two floating-point numbers X and Y(0.0<=X,Y<=1000.0).
25.000000 5.0000000.000000 0.00000010.000000 0.00000010.000000 10.0000001.000000 1.00000014.000000 8.222222
33.3340.69
For float may be not accurate enough, please use double instead of float.
详细题解:
这道题是一道数学水题。解决这道题的方法可以是求定积分的方法。而用定积分的方法,需要知道抛物线的方程表示和直线的方程表示;利用这两方程的表示进行定积分计算即可求出所要求得面积。。
由样例可知点坐标和面积的数据类型需要采用double型。输入P1,P2,P3的坐标(x0,y0),(x1,y1),(x2,y2);设直线的方程为kx+B=0,由P2,P3点可知 k=(y2-y1)/(x2-x2);B=y1-k*x1;设抛物线的方程为ax^2+bx+c=0,由P0,P1可知 a=(y1-y0)/((x1-x0)^2);可知抛物线的顶点坐标表示为(-b/(2*a),((4*a*c)-b^2)/4*a),即由P1(x0,y0)可知b=-2*a*x0,,c=a*x0^2+y0;所以所求面积S为 ax^2+bx+c-(kx+B)在下限为x1,上限为x2的情况下的定积分。
下面附上AC代码:
#include<stdio.h>int main(){int t,i;double x0,y0,x1,y1,x2,y2,k,b,a,s,m,n;while(~scanf("%d",&t)){for(i=0;i<t;i++){scanf("%lf%lf%lf%lf%lf%lf",&x0,&y0,&x1,&y1,&x2,&y2);k=(y2-y1)/(x2-x1); b=y1-k*x1; m=x0; n=y0; a=(y1-n)/((x1-m)*(x1-m)); s=(a*x2*x2*x2/3-(2*a*m+k)*x2*x2/2+(a*m*m+n-b)*x2)-(a*x1*x1*x1/3-(2*a*m+k)*x1*x1/2+(a*m*m+n-b)*x1); printf("%.2f\n",s);}}return 0;}
阅读全文
0 0
- HDU 1071 The area 详解
- hdu 1071 The area
- (hdu 1071)The area
- hdu 1071 The area
- hdu 1071 The Area
- HDU 1071 The area
- Hdu 1071 - The area
- HDU 1071 The area
- HDU 1071 The area
- hdu 1071 The area
- HDU 1071 The area
- hdu 1071 - The area
- hdu-1071 The area
- hdu 1071 The area
- The area (HDU 1071)
- hdu-1071-The area
- hdu 1071 The area
- HDU 1071 The area
- CFgym:Painting the Wall(BFS)
- Linux下安装mysql
- 开始,做一个自己不认识的人
- 详解mysql的for update
- 爬虫小程序
- HDU 1071 The area 详解
- 简单对金额大写转换的实现
- cmd运行python文件时出现中文乱码的问题
- Python3 基础语法
- PHP的MySQL操作
- ★实验 8-1 1. 创建一个守候进程。并为自己创建独立的日志文件。 2. 每隔 1s 向日志文件中写入如下信息: a) 未使用的内存大小(MemFree) 可以从/proc/meminf
- css css样式表 选择器 声明
- HIDAPI库交叉编译与应用
- mouse_event()函数控制鼠标操作