HDU 1724 Ellipse(数值积分の辛普森公式)
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 )
#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(数值积分の辛普森公式)的更多相关文章
- HDU 1724 Ellipse (自适应辛普森积分)
题目链接:HDU 1724 Problem Description Math is important!! Many students failed in 2+2's mathematical tes ...
- hdu 1724 Ellipse —— 自适应辛普森积分
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1724 函数都给出来了,可以用辛普森积分: 一开始 eps = 1e-8 TLE了,答案只要三位小数,那么 ...
- HDU - 1724 Ellipse 自适应辛普森模板
OJ 题解传送门 //Achen #include<algorithm> #include<iostream> #include<cstring> #include ...
- hdu 1724 Ellipse simpson积分
/* hdu 1724 Ellipse simpson积分 求椭圆的部分面积 simpson积分法 http://zh.wikipedia.org/zh-tw/%E8%BE%9B%E6%99%AE%E ...
- hdu 1724 Ellipse——辛普森积分
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1724 #include<cstdio> #include<cstring> #in ...
- HDU 1724 Ellipse [辛普森积分]
Ellipse Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 1724 Ellipse 【自适应Simpson积分】
Ellipse Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 1724 Ellipse
Problem Description Math is important!! Many students failed in 2+2’s mathematical test, so let's AC ...
- HDU 1724 Ellipse 自适应simpson积分
simpson公式是用于积分求解的比较简单的方法(有模板都简单…… 下面是simpson公式(很明显 这个公式的证明我并不会…… (盗图…… 因为一段函数基本不可能很规则 所以我们要用自适应积分的方法 ...
随机推荐
- CLR调试报错“Visual Studio远程调试监视器 (MSVSMON.EXE) 的 64 位版本无法调试 32 位进程或 32 位转储。请改用 32 位版本”的解决
Win7 64位电脑上进行visual studio的数据库项目的CLR存储过程进行调试时,报错: ---------------------------Microsoft Visual Studio ...
- php YAF
Yaf 的特点: 用C语言开发的PHP框架, 相比原生的PHP, 几乎不会带来额外的性能开销. 所有的框架类, 不需要编译, 在PHP启动的时候加载, 并常驻内存. 更短的内存周转周期, 提高内存利用 ...
- JNI字段描述符(转)
转载自http://fgsink.blog.163.com/blog/static/16716997020124310169911/ “([Ljava/lang/String;)V” 它是一种对函数返 ...
- Average Cost (AVCO) Method
http://accountingexplained.com/financial/inventories/avco-method Average Cost (AVCO) Method Aver ...
- centos 6.4 安装视频解码器
cd /etc/yum.repos.d/ wget http://mirrors.163.com/.help/CentOS6-Base-163.repo yum update rpm -Uhv htt ...
- SqlServer2008R2执行Sql语句,快捷键
SqlServer2008R2执行Sql语句,快捷键Alt+X
- ant 执行到javac时运行中止,怎么办?
今天下午我用ant,明明都能打出target.后来改了点代码就不行了,执行到compile的javac时运行中止,真是见鬼了. 在ant构建文件上右击,点击"run as"-> ...
- NavigationController popToViewController跳转之前任意ViewController方法
NSArray *viewControllers = self.navigationController.viewControllers;A *viewController = [viewContro ...
- iOS系统自带正则表达式简单运用
//组装一个字符串,把里面的网址解析出来 NSString *urlString = @"sfdshttp://www.baidu.com"; NSError *error; // ...
- marathon参考(11):ports端口设置(转)
Ports marathon中应用的端口配置可能被混淆,并有一个悬而未决的问题,需要重新设计 ports API.这个页面试图更清楚地解释它们是如何工作的. 定义 containerPort:在容器内 ...