HDU 1724:Ellipse(自适应辛普森积分)
题意
给出一个椭圆,问一个[l, r] 区间(蓝色区域)的面积是多少。
思路
具体一些分析如上。
很方便,套上公式就可以用了。
注意 eps 的取值影响了跑的时间,因为决定了递归的深度。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 11;
const double eps = 1e-5; // 精度对时间有影响
double a, b, l, r;
// 被积函数,这里是椭圆
double F(double x) {
return sqrt(b * b - b * b * x * x / a / a);
}
// 三点simpson法
double simpson(double a, double b) {
double c = a + (b - a) / 2; // (a + b) / 2
return (F(a) + 4 * F(c) + F(b)) * (b - a) / 6.0;
}
//自适应Simpson公式(递归过程).已知整个区间[a,b]上的三点Simpson值A
double asr(double a, double b, double eps, double A) {
double c = a + (b - a) / 2;
double L = simpson(a, c), R = simpson(c, b);
if(fabs(L + R - A) <= eps * 15) return L + R + (L + R - A) / 15.0;
return asr(a, c, eps / 2, L) + asr(c, b, eps / 2, R);
}
double ASR(double a, double b, double eps) {
return asr(a, b, eps, simpson(a, b));
}
int main() {
int t; scanf("%d", &t);
while(t--) {
scanf("%lf%lf%lf%lf", &a, &b, &l, &r);
printf("%.3f\n", ASR(l, r, eps) * 2);
} return 0;
}
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积分
simpson公式是用于积分求解的比较简单的方法(有模板都简单…… 下面是simpson公式(很明显 这个公式的证明我并不会…… (盗图…… 因为一段函数基本不可能很规则 所以我们要用自适应积分的方法 ...
- hdu 1724 : Ellipse 【Simpson积分】
题目链接 题意:给出椭圆方程中的a和b,再给出l.r,求l到r的积分的二倍. 输出时要求精度控制为保留到小数点后3位,如下代码中,eps设为1e-9 1e-8时均TLE,1e-4可以AC,1e-3会W ...
- hdu 1724 Ellipse simpson积分
/* hdu 1724 Ellipse simpson积分 求椭圆的部分面积 simpson积分法 http://zh.wikipedia.org/zh-tw/%E8%BE%9B%E6%99%AE%E ...
- 【自适应辛普森积分】hdu1724 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 ...
随机推荐
- AWS核心服务概览
1.Amazon Web Service 应该可以说,Amazon Web Service目前是云计算领域的领头羊,其业务规模.开发水平和盈利能力在业界内都是首屈一指的.从本科毕业离开学校就一直做Ja ...
- Ubuntu 官方推荐源列表
如何使用Ubuntu Night Ubuntu Night( http://ubuntu9.com ) 的Top mirror功能根据当前的网络情况和源健康状况不断地进行更新当前可用的源的信息,包括 ...
- 【值转换器】 WPF中Image数据绑定Icon对象
原文:[值转换器] WPF中Image数据绑定Icon对象 这是原来的代码: <Image Source="{Binding MenuIcon}" ...
- C# 不重启程序修改并保存配置文件(appSettings节点)
原文:C# 不重启程序修改并保存配置文件(appSettings节点) private static void UpdateAppConfig(string newKey, string newVal ...
- python 识别身份证号码
# !/usr/bin/python # -*-coding:utf-8-*- import sys import time time1 = time.time() from PIL import I ...
- ELINK编程器能用来做什么
以前 产品量产与测试的时候,在电脑上用JATG/SWD编程器或串口下载器等工具下载程序到产品中,效率低且操作复杂 现在 可以用ELINK脱机编程器来摆脱电脑并降低操作复杂度,只需把程序文件下载到 ...
- 自动启动 Windows 10 UWP 应用
原文: https://docs.microsoft.com/zh-cn/windows/uwp/xbox-apps/automate-launching-uwp-apps 简介 开发人员有多种选项可 ...
- CROSS JOIN
原文:CROSS JOIN 最近在讲到T-SQL查询的Join部分时,一下子没有想起来CROSS JOIN的用法,因为其实平常也确实基本不用到.特意找了一个例子,以供参考 CROSS JOIN又称为笛 ...
- UWP入门(十二)--数据绑定用法
原文:UWP入门(十二)--数据绑定用法 主要几个元素: Template DataTemplate ItemSource 数据绑定是一个数据提取的方法,能使数据和UI上的控件紧密相连,下面的Demo ...
- python 动态调用模块&类&方法
转载自:http://www.cnblogs.com/bluefrog/archive/2012/05/11/2496439.html 一直想知道python里有没有类似php中的 $classnam ...