【自适应辛普森积分】hdu1724 Ellipse
Ellipse
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2502 Accepted Submission(s): 1126
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 )
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
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]范围内的面积,多组数据
题解
自适应辛普森积分裸题
直接对某个区间进行辛普森积分的话公式为(r - l )*(f(l )+4 * f(( l + r )/ 2)+f( r ))/ 6
然后如果直接拆分所求区间的话,如果遇到鬼畜的函数就会使误差变大
所以就有了自适应辛普森积分
就是说我们求这个区间的辛普森积分和左右部分的辛普森积分
如果相差小于eps的话,就直接返回答案
否则递归计算左右区间
就酱
代码
#include<cstdio>
#include<iostream>
#include<cmath>
#define db double
using namespace std; db a,b,l,r;
int t; db f(db x)
{
return sqrt(b*b*(1.0-x*x/a/a));
} db xin(db l,db r)
{
db mid=(l+r)/;
return (r-l)*(f(l)+*f(mid)+f(r))/6.0;
} db getans(db x,db y,db eps,db val)
{
db mid=(x+y)/;
db aa=xin(x,mid),bb=xin(mid,y);
if(fabs(val-aa-bb)<=eps*15.0) return aa+bb+(aa+bb-val)/15.0;
return getans(x,mid,eps/2.0,aa)+getans(mid,y,eps/2.0,bb);
} int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf%lf",&a,&b,&l,&r);
printf("%.3lf\n",2.0*getans(l,r,0.00005,xin(l,r)));
}
return ;
}
【自适应辛普森积分】hdu1724 Ellipse的更多相关文章
- HDU 1724 Ellipse (自适应辛普森积分)
题目链接:HDU 1724 Problem Description Math is important!! Many students failed in 2+2's mathematical tes ...
- HDU 1724:Ellipse(自适应辛普森积分)
题目链接 题意 给出一个椭圆,问一个[l, r] 区间(蓝色区域)的面积是多少. 思路 自适应辛普森积分 具体一些分析如上. 很方便,套上公式就可以用了. 注意 eps 的取值影响了跑的时间,因为决定 ...
- hdu 1724 Ellipse —— 自适应辛普森积分
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1724 函数都给出来了,可以用辛普森积分: 一开始 eps = 1e-8 TLE了,答案只要三位小数,那么 ...
- [BZOJ1502]月下柠檬树(自适应辛普森积分)
1502: [NOI2005]月下柠檬树 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1387 Solved: 739[Submit][Status] ...
- 洛谷 P4525 & P4526 [模板] 自适应辛普森积分
题目:https://www.luogu.org/problemnew/show/P4525 https://www.luogu.org/problemnew/show/P4526 学习辛普森积分:h ...
- BZOJ2178 圆的面积并 计算几何 辛普森积分
原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2178.html 题目传送门 - BZOJ2178 题意 给出 $n(n\leq 1000)$ 个圆,求 ...
- 【BZOJ2178】圆的面积并(辛普森积分)
[BZOJ2178]圆的面积并(辛普森积分) 题面 BZOJ 权限题 题解 把\(f(x)\)设为\(x\)和所有圆交的线段的并的和. 然后直接上自适应辛普森积分. 我精度死活一个点过不去,不要在意我 ...
- 洛谷P4525 【模板】自适应辛普森法1(simpson积分)
题目描述 计算积分 结果保留至小数点后6位. 数据保证计算过程中分母不为0且积分能够收敛. 输入输出格式 输入格式: 一行,包含6个实数a,b,c,d,L,R 输出格式: 一行,积分值,保留至小数点后 ...
- HDU - 1071 - The area - 高斯约旦消元法 - 自适应辛普森法积分
http://acm.hdu.edu.cn/showproblem.php?pid=1071 解一个给定三个点的坐标二次函数某区域的积分值. 设出方程之后高斯消元得到二次函数.然后再消元得到直线. 两 ...
随机推荐
- java线程间通信:一个小Demo完全搞懂
版权声明:本文出自汪磊的博客,转载请务必注明出处. Java线程系列文章只是自己知识的总结梳理,都是最基础的玩意,已经掌握熟练的可以绕过. 一.从一个小Demo说起 上篇我们聊到了Java多线程的同步 ...
- UEP-多任务
打开多任务 Function testTabTask(){ openTabTask(","多任务测试",$$pageContextPath+"/componen ...
- vhost:一种 virtio 高性能的后端驱动实现
什么是 vhost vhost 是 virtio 的一种后端实现方案,在 virtio 简介中,我们已经提到 virtio 是一种半虚拟化的实现方案,需要虚拟机端和主机端都提供驱动才能完成通信,通常, ...
- 01 mysql的安装(windows)
在安装mysql之前,一般是先下载mysql,推荐大家去Oracle的官网下载,而且尽量使用免安装的版本(即压缩版,解压之后就可以使用的版本,不是.exe的安装版本),因为安装版的mysql在安装过程 ...
- 织梦dedecms如何去除版权中的Power by DedeCms
很多站长在使用dedecms建站过程中,很多人都会调用到dedecms自带的powerby标签,这样在版权信息中就会多出Power by DedeCms这个连接.今天教大家如何去除. 工具/原料 de ...
- 在form里面,放了四个UEditor,怎么在后台分别获取它们值
1) 默认情况下提交到后台的表单名称是 "editorValue",在editor_config.js中可以配置,参数名为textarea. 2) 可以在容器标签(即script标 ...
- 织梦dedeCMS留言薄
dedeCMS留言薄模塊名爲guestbook, 留言薄模板:/templets/plus/guestbook.htm; 留言回覆模板: 管理員回覆調用/templets/plus/guestbook ...
- @synchronized(self)
@synchronized 的作用是创建一个互斥锁,保证此时没有其它线程对self对象进行修改.这个是objective-c的一个锁定令牌,防止self对象在同一时间内被其 它线程访问,起到线程的保护 ...
- jQuery——动态给表格添加序号
摘录自:http://www.cnblogs.com/picaso/archive/2012/10/08/2715564.html 很多时候遇到需要对表格动态操作,而且一般都会有表格的序号,但是有时候 ...
- python实现冒泡排序和快速排序
冒泡排序和快排的python实现: data = [1, 3, 5, 10, 4, 7] times = 0 "冒泡排序" for i in range(len(data)): f ...