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.
 
题目大意:给椭圆的a、b参数,求区间[l, r]的椭圆积分的和。
思路:直接套用辛普森公式,贴个模板。
 
代码(93MS):
 #include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std; double fa, fb, fl, fr;
int n; double sqr(double x) {
return x * x;
} double func(double x) {
return * sqrt(sqr(fb) * ( - sqr(x) / sqr(fa)));
} double simpson(double a, double b) {
double mid = a + (b - a) / ;
return (func(a) + * func(mid) + func(b)) * (b - a) / ;
} double asr(double a, double b, double eps, double A) {
double mid = a + (b - a) / ;
double l = simpson(a, mid), r = simpson(mid, b);
if(fabs(l + r - A) <= * eps) return l + r + (l + r - A) / ;
return asr(a, mid, eps / , l) + asr(mid, b, eps / , r);
} double asr(double a, double b, double eps) {
return asr(a, b, eps, simpson(a, b));
} int main() {
scanf("%d", &n);
while(n--) {
scanf("%lf%lf%lf%lf", &fa, &fb, &fl, &fr);
printf("%.3f\n", asr(fl, fr, 1e-));
}
}

HDU 1724 Ellipse(数值积分の辛普森公式)的更多相关文章

  1. HDU 1724 Ellipse (自适应辛普森积分)

    题目链接:HDU 1724 Problem Description Math is important!! Many students failed in 2+2's mathematical tes ...

  2. hdu 1724 Ellipse —— 自适应辛普森积分

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1724 函数都给出来了,可以用辛普森积分: 一开始 eps = 1e-8 TLE了,答案只要三位小数,那么 ...

  3. HDU - 1724 Ellipse 自适应辛普森模板

    OJ 题解传送门 //Achen #include<algorithm> #include<iostream> #include<cstring> #include ...

  4. hdu 1724 Ellipse simpson积分

    /* hdu 1724 Ellipse simpson积分 求椭圆的部分面积 simpson积分法 http://zh.wikipedia.org/zh-tw/%E8%BE%9B%E6%99%AE%E ...

  5. hdu 1724 Ellipse——辛普森积分

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1724 #include<cstdio> #include<cstring> #in ...

  6. HDU 1724 Ellipse [辛普森积分]

    Ellipse Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  7. HDU 1724 Ellipse 【自适应Simpson积分】

    Ellipse Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  8. HDU 1724 Ellipse

    Problem Description Math is important!! Many students failed in 2+2’s mathematical test, so let's AC ...

  9. HDU 1724 Ellipse 自适应simpson积分

    simpson公式是用于积分求解的比较简单的方法(有模板都简单…… 下面是simpson公式(很明显 这个公式的证明我并不会…… (盗图…… 因为一段函数基本不可能很规则 所以我们要用自适应积分的方法 ...

随机推荐

  1. Jquery小例子:全选按钮、加事件、挂事件;parent()语法;slideToggle()语法;animate()语法;元素的淡入淡出效果:fadeIn() 、fadeOut()、fadeToggle() 、fadeTo();function(e):e包括事件源和时间数据;append() 方法

    function(e): 事件包括事件源和事件数据,事件源是指是谁触发的这个事件,谁就是事件源(div,按钮,span都可以是事件源),时间数据是指比如点击鼠标的事件中,事件数据就是指点击鼠标的左建或 ...

  2. css3常用动画效果集合01

    /*由右到左进场*/ .FromRightToLeft{ -webkit-animation:FromRightToLeft 500s .2s ease both; } @-webkit-keyfra ...

  3. Mac废纸篓 不能完全清空的有效解决方法

    摘自:http://www.neonan.com/articles/5582 对于苹果用户来说, 可能都会遇到过这样的情况(尽管这种情况是不常出现的!), Mac OS X系统突然出现一些顽固的文件家 ...

  4. JMeter学习-006-Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002 解决办法(windows 7)

    好久没用 JMeter 了,今天启动的时候,发现启动命令行窗口出现了警报,警告信息如下图所示:

  5. Latency

    1)在网络,延迟时间(latency),同义词为延迟,是表示从特定点得到一个数据包(packet)所花的时间.在一些情况下(例如,AT&T),延迟时间用发送出包到回到发送端这个运行一周的时间就 ...

  6. (转)linux运行tomcat时JRE_HOME显示不对怎么办?

    PS:以前也没出现这些问题,重装了一下系统,感觉什么都让我撞上了.Using CATALINA_BASE:   /usr/share/tomcat7Using CATALINA_HOME:   /us ...

  7. Android系统框架

    从上图中可以看出,Android系统架构为四层结构,从上层到下层分别是应用程序层.应用程序框架层.系统运行库层以及Linux内核层 应用程序层: 简单说就是我们用户肉眼能看到的应用程序,如SMS短信客 ...

  8. Android studio关于真机调试DDMS中的data文件夹打不开的解决方法

    由于做开发的时候想打开查看数据库存放的内容,在eclipse中数据库文件默认就在/data/data/应用包名/databases/数据库名,而用Android studio打开DDMS下面找时发现点 ...

  9. 判断远程图片是否存在【适用于windows服务器】

    <?php function file_exists2($url) { if(@file_get_contents($url,0,null,0,1)) return 1; else return ...

  10. [GeoServer]Openlayers简单调用

    Openlayers Demo: <html> <head> <title>OpenLayers Example</title> <script ...