必威体育Betway必威体育官网
当前位置:首页 > IT技术

HDU1724-辛普森积分公式法求椭圆面积

时间:2019-10-11 13:13:25来源:IT技术作者:seo实验室小编阅读:84次「手机版」
 

椭圆面积公式

Ellipse

Time limit: 1000/1000 MS (java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1061    Accepted Submission(s): 388

Problem Description

Math is important!! Many students failed in 2+2’s mathematical test, so let's AC this problem to mourn for our lost youth..

Look this sample picture:

A ellipses in the plane and center in point O. the L,R lines will be vertical through the X-axis. The problem is calculating the blue intersection area. But calculating the intersection area is dull, so I have turn to you, a talent of programmer. Your task is tell me the result of calculations.(defined PI=3.14159265 , The area of an ellipse A=PI*a*b )

Input

Input may contain multiple test cases. The first line is a positive integer N, denoting the number of test cases below. One case One line. The line will consist of a pair of integers a and b, denoting the ellipse equation , A pair of integers l and r, mean the L is (l, 0) and R is (r, 0). (-a <= l <= r <= a).

Output

For each case, output one line containing a float, the area of the intersection, accurate to three decimals after the decimal point.

Sample Input


 

2 2 1 -2 2 2 1 0 2

Sample Output


 

6.283 3.142

Author

威士忌

Source

HZIEE 2007 Programming Contest

Run ID Submit Time Judge Status Pro.ID Exe.Time Exe.Memory Code Len. Language Author
10006793 2014-01-21 21:22:02 Accepted 1724 468MS 316K 628 B C++  

思路:

这道题目的意思是:求出所给椭圆的蓝色阴影部分面积。由于阴影部分是不规则图形,所以,可以考虑用数值分析的办法-

辛普森公式或者牛顿-科特斯公式求积分法,更多的公式见数值分析教材,辛普森的公式如下,为了增加精度,可以用二分法

迭代细化。

这是核心公式,具体实现见代码:(这种办法的效率真不怎么样,跑了400ms)

#include <iOStream>
#include <math.h>
using namespace std;

const double esp = 1e-10;
double a,b;

double f(double x)
{
	return b * sqrt(1.0-(x*x)/(a*a));
}

double simpson(double l,double r)
{
	return (f(l)+4*f((l+r)/2.0)+f(r))/6.0*(r-l);
}

double integral(double l,double r)
{
	double mid = (l+r)/2.0;
	double res = simpson(l,r);
	if (fabs(res-simpson(l,mid)-simpson(mid,r)) < esp)
		return res;
	else
		return integral(l,mid) + integral(mid,r);
}
int main()
{
	int T;
	double l,r;
	cin >> T;
	while (T--)
	{
		cin >> a >> b >> l >> r;
		printf("%.3lf\n",2*integral(l,r));
	}
	return 0;
}

相关阅读

傅里叶变换和拉普拉斯变换公式总结

因为傅里叶变换之类的很常用,时间长了不用总会忘记,所以一次性罗列出来权当总结好了。主要参考《信号与线性系统分析》(吴大正),也有

路漫漫其修远兮 吾将上下而求索

codeblocks编码问题原因及解决方案 一:codeblock中有3类字符集 1. 文件字符集: (1) 源文件本身也是文本文件,所以源文件字符集是指

对数的计算公式

复制 https://www.cnblogs.com/ransn/p/5138643.html   对数的计算公式 性质编辑 ① ; ②  ; ③负数与零无对数. ④ * 

各种三角形边长的计算公式

解直角三角形(斜三角形特殊情况): 勾股定理,只适用于直角三角形(外国叫“毕达哥拉斯定理”) a^2+b^2=c^2, 其中a和b分别为直角三角形两

卷积公式的理解

卷积公式的由来 卷积公式与Laplace变换的联系Laplace变换公式:F(s)=∫0∞f(t)e−stdtG(s)=∫0∞g(t)e−stdtF(s) = \int_0^\in

分享到:

栏目导航

推荐阅读

热门阅读