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. duplicate symbol _OBJC_CLASS 错误处理方法

    错误: ld: duplicate symbol _OBJC_CLASS_$_************ in **************** 一种可能性是你的项目的不同group里有着相同名称的类 ...

  2. Bash 快捷键大全

    快捷键的一些说明: CTRL=C:这个键是指PC键盘上的Ctrl键 ALT=M:这个键是PC键盘上的ALT键,如果你键盘上没有这个键,可以尝试使用ESC键代替 SHIFT=S:此键是PC上的Shift ...

  3. block 反向传值回调

    /** *  block 反向传值回调 */ //在第二个控制器中 //   (1)声明block,在基类中已写好 //   (2)写好传值方法 //(1) typedef void (^Return ...

  4. nginx支持cgi(c,c++)

    前段时间用我修改了tinyhttpd,让其cgi支持文件流,感觉满小巧,就应用上了.最近访问请求量上来而来,它对socket的各种异常状态处理不好,对于慢速的链接会占用我的线程.虽然我一直想仿出ten ...

  5. Oracle 11G INDEX FULL SCAN 和 INDEX FAST FULL SCAN 对比分析

    SQL> drop table test; 表已删除. SQL> create table test as select * from dba_objects where 1!=1; 表已 ...

  6. Fast and Robust Hand Tracking Using Detection-Guided Optimization

    http://handtracker.mpi-inf.mpg.de/projects/FastHandTracker/

  7. POJ1326问题描述

    Description Mileage program of ACM (Airline of Charming Merlion) is really nice for the travelers fl ...

  8. Ball Tracking with OpenCV

    http://www.pyimagesearch.com/2015/09/14/ball-tracking-with-opencv/

  9. axis2_1.6.2之构建web端和客户端 .

    参考资料: http://blog.csdn.net/apei830/article/details/5448897 axis2的官网 http://axis.apache.org/axis2/jav ...

  10. Android --设置Toast消失时间

    参考博客:Android开发,Toast重复显示(显示时间过长)解决方法 package com.dr.app.drseamoniter.toast; import android.content.C ...