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. CLR调试报错“Visual Studio远程调试监视器 (MSVSMON.EXE) 的 64 位版本无法调试 32 位进程或 32 位转储。请改用 32 位版本”的解决

    Win7 64位电脑上进行visual studio的数据库项目的CLR存储过程进行调试时,报错: ---------------------------Microsoft Visual Studio ...

  2. php YAF

    Yaf 的特点: 用C语言开发的PHP框架, 相比原生的PHP, 几乎不会带来额外的性能开销. 所有的框架类, 不需要编译, 在PHP启动的时候加载, 并常驻内存. 更短的内存周转周期, 提高内存利用 ...

  3. JNI字段描述符(转)

    转载自http://fgsink.blog.163.com/blog/static/16716997020124310169911/ “([Ljava/lang/String;)V” 它是一种对函数返 ...

  4. Average Cost (AVCO) Method

    http://accountingexplained.com/financial/inventories/avco-method   Average Cost (AVCO) Method   Aver ...

  5. centos 6.4 安装视频解码器

    cd /etc/yum.repos.d/ wget http://mirrors.163.com/.help/CentOS6-Base-163.repo yum update rpm -Uhv htt ...

  6. SqlServer2008R2执行Sql语句,快捷键

    SqlServer2008R2执行Sql语句,快捷键Alt+X

  7. ant 执行到javac时运行中止,怎么办?

    今天下午我用ant,明明都能打出target.后来改了点代码就不行了,执行到compile的javac时运行中止,真是见鬼了. 在ant构建文件上右击,点击"run as"-> ...

  8. NavigationController popToViewController跳转之前任意ViewController方法

    NSArray *viewControllers = self.navigationController.viewControllers;A *viewController = [viewContro ...

  9. iOS系统自带正则表达式简单运用

    //组装一个字符串,把里面的网址解析出来 NSString *urlString = @"sfdshttp://www.baidu.com"; NSError *error; // ...

  10. marathon参考(11):ports端口设置(转)

    Ports marathon中应用的端口配置可能被混淆,并有一个悬而未决的问题,需要重新设计 ports API.这个页面试图更清楚地解释它们是如何工作的. 定义 containerPort:在容器内 ...