YT14-HDU-求抛物线与直线间的面积(积分)
2015-02-05 21:49
323 查看
Problem Description
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 thearea of the land?
Note: The point P1 in the picture is the vertex of the parabola.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.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).
Output
For each test case, you should output the area of the land, the result should be rounded to 2 decimal places.
Sample Input
2 5.000000 5.000000 0.000000 0.000000 10.000000 0.000000 10.000000 10.000000 1.000000 1.000000 14.000000 8.222222
Sample Output
33.33 40.69
Hint
For float may be not accurate enough, please use double instead of float.代码如下:
#include <iostream> #include <iomanip> using namespace std; int main() { int T; double x1,y1,x2,y2,x3,y3,a,k,s; cin>>T; while(T--) { cin>>x1>>y1>>x2>>y2>>x3>>y3; a=(y2-y1)/((x2-x1)*(x2-x1)); k=(y2-y3)/(x2-x3); s=a/3*(x3*x3*x3-x2*x2*x2)+(a*x1*x1+k*x3+y1-y3)*(x3-x2)+0.5*(2*a*x1+k)*(x2*x2-x3*x3); cout<<setiosflags(ios::fixed)<<setprecision(2)<<s<<endl; } return 0; }
运行结果图片由于当时做题后没有保存,就不再上传了。
这道题考得是求抛物线方程y=ax^2+bx+c中啊a,b,c的值,然后就是微积分,提交的这个代码是在百度上找的,但没有分析,所以我也没怎么看懂,反而是另一位的代码差不多理解了
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int main() { double x1,x2,x3,y1,y2,y3,a,b,c,p,q,r,k,d,ans; int T; scanf("%d",&T); while(T--) { scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3); p=y1/((x1-x2)*(x1-x3)); q=y2/((x2-x1)*(x2-x3)); r=y3/((x3-x1)*(x3-x2)); a=p+q+r; b=-p*(x2+x3)-q*(x1+x3)-r*(x1+x2); c=p*x2*x3+q*x1*x3+r*x1*x2; k=(y3-y2)/(x3-x2);//直线的斜率 d=y2-k*x2;//直线的截距 ans=1.0/3.0*a*(x3*x3*x3-x2*x2*x2)+0.5*(b-k)*(x3*x3-x2*x2)+(c-d)*(x3-x2); printf("%.2lf\n",ans); } return 0; }
设已知3点为(x1,y1),(x2,y2),(x3,y3) 方程设为 y=a*x^2+b*x+c;
令 p=y1/((x1-x2)*(x1-x3)); q=y2/((x2-x1)*(x2-x3)); r=y3/((x3-x1)*(x3-x2));
则 a=p+q+r; b=-p*(x2+x3)-q*(x1+x3)-r*(x1+x2); c=p*x2*x3+q*x1*x3+r*x1*x2;
然后就是微分了。
相关文章推荐
- HDU 1071 The area && 抛物线与直线积分面积
- hdu1071(积分求直线和抛物线构成的面积)
- HDU_1071——积分求面积,抛物线顶点公式
- HDU-不定积分-求一条直线与抛物线所围成的面积
- HDU 1071 The area(抛物线与直线围成的面积)
- HDU 2528 Area (求直线与线段的交点后求面积)
- HDU 1071 The area (定积分求面积)
- hdu 1071 The area 高数积分求面积~~~~小水题~~
- HDU 1071 The area(数学 抛物线 积分)
- HDU 1071(2013.9.21周赛A题:抛物线面积)
- ACM--抛物线和直线围成的面积–-HDOJ 1071--The area--水
- HDU 4752 Polygon(抛物线长度积分)
- hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)
- Hdu 1071 The area (抛物线 简单定积分)
- hdu 1071 the area 用积分求面积
- 求抛物线直线相交面积题(Problem ID:1071)
- 求抛物线与直线形成的面积(数学)
- hdu 1071 The area(定积分求面积)
- The area(抛物线与直线的相交面积)
- 求抛物线与直线相交面积