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):
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. double fa, fb, fl, fr;
  9. int n;
  10.  
  11. double sqr(double x) {
  12. return x * x;
  13. }
  14.  
  15. double func(double x) {
  16. return * sqrt(sqr(fb) * ( - sqr(x) / sqr(fa)));
  17. }
  18.  
  19. double simpson(double a, double b) {
  20. double mid = a + (b - a) / ;
  21. return (func(a) + * func(mid) + func(b)) * (b - a) / ;
  22. }
  23.  
  24. double asr(double a, double b, double eps, double A) {
  25. double mid = a + (b - a) / ;
  26. double l = simpson(a, mid), r = simpson(mid, b);
  27. if(fabs(l + r - A) <= * eps) return l + r + (l + r - A) / ;
  28. return asr(a, mid, eps / , l) + asr(mid, b, eps / , r);
  29. }
  30.  
  31. double asr(double a, double b, double eps) {
  32. return asr(a, b, eps, simpson(a, b));
  33. }
  34.  
  35. int main() {
  36. scanf("%d", &n);
  37. while(n--) {
  38. scanf("%lf%lf%lf%lf", &fa, &fb, &fl, &fr);
  39. printf("%.3f\n", asr(fl, fr, 1e-));
  40. }
  41. }

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. linux 冒号的用途

    用途说明 我们知道,在Linux系统中,冒号(:)常用来做路径的分隔符(PATH),数据字段的分隔符(/etc/passwd)等.其实,冒号(:)在Bash中也是一个内建命令,它啥也不做,是个空命令. ...

  2. 获取枚举Description 属性

    /// <summary> /// 获取枚举变量值的 Description 属性 /// </summary> /// <param name="obj&qu ...

  3. Mixing Delphi and C++(相互调用)

    Mixing Delphi and C++ You have a TStringList and <algorithm>. What can you do? Quite a lot, ac ...

  4. Jquery调用webService的四种方法

    1.编写4种WebService方法 [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(Conf ...

  5. JS之toString方法

    1.JS中几乎每个值都有toString方法,null和undefined除外 2.对于字符串形式的值也可以使用toString()方法,返回该字符串的一个副本 3.toString(radix)方法 ...

  6. debian linux下配置lnmp环境

    用到哪些就安装哪些 安装配置时遇到: deb cdrom:[Debian GNU/Linux 7.1.0 _Wheezy_ - Official amd64 CD Binary-1 20130615- ...

  7. android 打开软件出现红框

    android打开软件的时候会出现红框,剑锋之前解了这个问题.fork过来,方便以后查看. 参考链接: http://www.cnblogs.com/zengjfgit/p/5377744.html ...

  8. XPS1330 作为Linux服务器之安装配置计划

      # Task 状态 完成时间 备注 博文链接  1.  打通SSH  未开始  --  安装系统后已经具备  --  2.  打通FTP  未开始  --  安装系统后已经具备  --  3.   ...

  9. SQL、LINQ、Lambda 三种用法(转)

    SQL.LINQ.Lambda 三种用法颜色注释: SQL LinqToSql Lambda QA1. 查询Student表中的所有记录的Sname.Ssex和Class列.select sname, ...

  10. iOS:app直播---采集篇

    [如何快速的开发一个完整的iOS直播app](采集篇) 转载自简书@袁峥Seemygo:http://www.jianshu.com/p/c71bfda055fa 前言 开发一款直播app,首先需要采 ...