HDU-不定积分-求一条直线与抛物线所围成的面积
来源:互联网 发布:js 中英文首字母排序 编辑:程序博客网 时间:2024/05/20 18:42
问题及代码:
运行结果:
求不定积分。
/* *Copyright (c)2014,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:area.cpp *作 者:单昕昕 *完成日期:2015年2月3日 *版 本 号:v1.0 * *问题描述: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.*程序输入: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).*程序输出:For each test case, you should output the area of the land, the result should be rounded to 2 decimal places.Sample Input25.000000 5.0000000.000000 0.00000010.000000 0.00000010.000000 10.0000001.000000 1.00000014.000000 8.222222Sample Output33.3340.69HintFor float may be not accurate enough, please use double instead of float.*///我写的代码,测试结果是对的,但是WA了,不知道问题出在哪。#include <iostream>#include<iomanip>#include<cmath>using namespace std;#define N 1000int main(){ int t; double x1,x2,x3,y1,y2,y3,s,y,h,a; cin>>t; while(t--) { cin>>x1>>y1>>x2>>y2>>x3>>y3; int i; a=(y2-y1)/((x2-x1)*(x2-x1)); s=(a*(x2-x1)*(x2-x1)+y1-(y2+((x2-x2)*(y3-y2))/(x3-x2))+a*(x3-x1)*(x3-x1)+y1-(y2+((x3-x2)*(y3-y2))/(x3-x2)))/2.0; h=(x3-x2)/N; for(i=1; i<N; i++) { y=x2+i*h; s+=(a*(y-x1)*(y-x1)+y1-(y2+((y-x2)*(y3-y2))/(x3-x2))); } cout<<setiosflags(ios::fixed)<<setprecision(2)<<s*h<<endl; } return 0;}//AC代码,网上找的。#include <stdio.h>#include <math.h>const double e=1e-3; //控制精度double a,h,d;double fx(double x){ return a*(x-h)*(x-h)+d;}double area(double x1,double y1,double x2,double y2,double x3,double y3){ double d1,d2,d3,p,s,x4,y4; d1=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)); if (d1<e) return 0; //精度有限 d2=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3)); d3=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); //求出3条边长 p=(d1+d2+d3)/2; s=sqrt(p*(p-d1)*(p-d2)*(p-d3)); //海伦公式求三角形面积 x4=(x1+x2)/2; y4=fx(x4); s+=area(x4,y4,x1,y1,x2,y2); x4=(x1+x3)/2; y4=fx(x4); s+=area(x4,y4,x1,y1,x3,y3); //二分法 求余下的面积 return s;}int main(){ double x1,y1,x2,y2,x3,y3,s; int n,i; scanf("%d",&n); for (i=0;i<n;i++) { scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3); h=x1; d=y1; a=(y2-d)/(x2-h)/(x2-h); //求二次函数解析式 s=area(x1,y1,x2,y2,x3,y3); printf("%.2lf\n",s); }}
运行结果:
求不定积分。
学习心得:
我是用高数学的面积求法写出的代码,求大神看看为什么WA了。。
AC代码是将所围成的图形分割成一个三角形和两个弓形来逼近求得。
0 0
- HDU-不定积分-求一条直线与抛物线所围成的面积
- HDU 1071 The area(抛物线与直线围成的面积)
- YT14-HDU-求抛物线与直线间的面积(积分)
- 求抛物线与直线形成的面积(数学)
- 求抛物线与直线相交面积
- hdu1071(积分求直线和抛物线构成的面积)
- HDU 1071 The area && 抛物线与直线积分面积
- ACM--抛物线和直线围成的面积–-HDOJ 1071--The area--水
- 坐标系中直线所围成的阴影面积
- 求抛物线直线相交面积题(Problem ID:1071)
- 直线与抛物线的交点
- HDU 2528 Area (求直线与线段的交点后求面积)
- 求关于一条直线的对称点
- 判断一条直线到另一条直线所构成的角度是逆时针还是顺时针方向。
- 不定积分的概念与性质
- 怎样才能动态演示直线与平面所成的角
- 过抛物线2交点的直线方程
- Leetcode 149 穷举法找出坐标系点集所成直线中涵盖点最多的一条
- chrome 插件收藏
- java写csv文件
- Struts2 异常处理 ( jsp记录异常信息到日志 )
- 关于oracle闪回日志增长问题
- 关于GPL协议的理解(开源与商用、免费与收费的理解)
- HDU-不定积分-求一条直线与抛物线所围成的面积
- Palindrome Partitioning
- UVA 11440 Help Mr. Tomisu 欧拉phi函数
- is null 和 is not null 都不能利用 索引
- oracle--表和视图
- Foundation框架: 4.常用结构体 - NSRect/CGRect
- RCPTT[Eclipse测试工具]简介
- LaTeX学习教程
- linux系统:"ping: unknown host www.baidu.com"