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公式(很明显 这个公式的证明我并不会…… (盗图…… 因为一段函数基本不可能很规则 所以我们要用自适应积分的方法 ...
随机推荐
- linux 冒号的用途
用途说明 我们知道,在Linux系统中,冒号(:)常用来做路径的分隔符(PATH),数据字段的分隔符(/etc/passwd)等.其实,冒号(:)在Bash中也是一个内建命令,它啥也不做,是个空命令. ...
- 获取枚举Description 属性
/// <summary> /// 获取枚举变量值的 Description 属性 /// </summary> /// <param name="obj&qu ...
- Mixing Delphi and C++(相互调用)
Mixing Delphi and C++ You have a TStringList and <algorithm>. What can you do? Quite a lot, ac ...
- Jquery调用webService的四种方法
1.编写4种WebService方法 [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(Conf ...
- JS之toString方法
1.JS中几乎每个值都有toString方法,null和undefined除外 2.对于字符串形式的值也可以使用toString()方法,返回该字符串的一个副本 3.toString(radix)方法 ...
- debian linux下配置lnmp环境
用到哪些就安装哪些 安装配置时遇到: deb cdrom:[Debian GNU/Linux 7.1.0 _Wheezy_ - Official amd64 CD Binary-1 20130615- ...
- android 打开软件出现红框
android打开软件的时候会出现红框,剑锋之前解了这个问题.fork过来,方便以后查看. 参考链接: http://www.cnblogs.com/zengjfgit/p/5377744.html ...
- XPS1330 作为Linux服务器之安装配置计划
# Task 状态 完成时间 备注 博文链接 1. 打通SSH 未开始 -- 安装系统后已经具备 -- 2. 打通FTP 未开始 -- 安装系统后已经具备 -- 3. ...
- SQL、LINQ、Lambda 三种用法(转)
SQL.LINQ.Lambda 三种用法颜色注释: SQL LinqToSql Lambda QA1. 查询Student表中的所有记录的Sname.Ssex和Class列.select sname, ...
- iOS:app直播---采集篇
[如何快速的开发一个完整的iOS直播app](采集篇) 转载自简书@袁峥Seemygo:http://www.jianshu.com/p/c71bfda055fa 前言 开发一款直播app,首先需要采 ...