Ellipse

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2502    Accepted Submission(s): 1126

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.
 
Sample Input
2
2 1 -2 2
2 1 0 2
 
Sample Output
6.283
3.142
 
Author
威士忌

题意

给定椭圆的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的更多相关文章

  1. HDU 1724 Ellipse (自适应辛普森积分)

    题目链接:HDU 1724 Problem Description Math is important!! Many students failed in 2+2's mathematical tes ...

  2. HDU 1724:Ellipse(自适应辛普森积分)

    题目链接 题意 给出一个椭圆,问一个[l, r] 区间(蓝色区域)的面积是多少. 思路 自适应辛普森积分 具体一些分析如上. 很方便,套上公式就可以用了. 注意 eps 的取值影响了跑的时间,因为决定 ...

  3. hdu 1724 Ellipse —— 自适应辛普森积分

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1724 函数都给出来了,可以用辛普森积分: 一开始 eps = 1e-8 TLE了,答案只要三位小数,那么 ...

  4. [BZOJ1502]月下柠檬树(自适应辛普森积分)

    1502: [NOI2005]月下柠檬树 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1387  Solved: 739[Submit][Status] ...

  5. 洛谷 P4525 & P4526 [模板] 自适应辛普森积分

    题目:https://www.luogu.org/problemnew/show/P4525 https://www.luogu.org/problemnew/show/P4526 学习辛普森积分:h ...

  6. BZOJ2178 圆的面积并 计算几何 辛普森积分

    原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2178.html 题目传送门 - BZOJ2178 题意 给出 $n(n\leq 1000)$ 个圆,求 ...

  7. 【BZOJ2178】圆的面积并(辛普森积分)

    [BZOJ2178]圆的面积并(辛普森积分) 题面 BZOJ 权限题 题解 把\(f(x)\)设为\(x\)和所有圆交的线段的并的和. 然后直接上自适应辛普森积分. 我精度死活一个点过不去,不要在意我 ...

  8. 洛谷P4525 【模板】自适应辛普森法1(simpson积分)

    题目描述 计算积分 结果保留至小数点后6位. 数据保证计算过程中分母不为0且积分能够收敛. 输入输出格式 输入格式: 一行,包含6个实数a,b,c,d,L,R 输出格式: 一行,积分值,保留至小数点后 ...

  9. HDU - 1071 - The area - 高斯约旦消元法 - 自适应辛普森法积分

    http://acm.hdu.edu.cn/showproblem.php?pid=1071 解一个给定三个点的坐标二次函数某区域的积分值. 设出方程之后高斯消元得到二次函数.然后再消元得到直线. 两 ...

随机推荐

  1. SPRING BOOT跨域访问处理

    尊重原创:http://blog.csdn.net/ruiguang21/article/details/77878933 问题场景:由于项目中使用到跨域访问,今天也得到高人指点,所以写出来分享给大家 ...

  2. 将TinyXml快速入门的接口面向对象化(转载)

    作者:朱金灿 来源:http://www.cnblogs.com/clever101 在TinyXml快速入门的系列文章中(详情见本博客),我只是将tinyxml类库解析xml文件的类封装为API接口 ...

  3. radiobutton独特属性

    radiobutton是通过name来分组的,也就是说,使用相同的名字的radio,它们才是单选的,如果名字不同的radio,是不具备这个效果的,这个是第一要点. 第二,针对不同的radio(name ...

  4. 从零开始学习前端JAVASCRIPT — 5、JavaScript基础BOM

    1:BOM(Browser  Object  Model)概念 window对象是BOM中所有对象的核心. 2:window属性(较少用) self:self代表自己,相当于window. windo ...

  5. Linux 安装及配置 Nginx + ftp 服务器

    Nginx 安装及配置 一.Nginx 简介: Nginx("engine x") 是一款是由俄罗斯的程序设计师 Igor Sysoev 所开发高性能的 Web和 反向代理服务器, ...

  6. 修真院java后端工程师学习课程--任务1(day one)

    这是我从学习资料-线下报名-北京报名截取的报名截图,从图中我们可以看出我们的报名对象应该有姓名,qq,修真类型,预计入学时间,毕业院校,线上学号,日报链接,立愿,辅导师兄等属性,其中线上学号是主码. ...

  7. C#进行CAD二次开发环境配置

    最近被公司分配到了做CAD二次开发.也是初次接触这方面的东西,其实是有些无从下手的感觉.因为公司这边也没有人有时间带我,只能是自己看书,然后再写一些Demo,再结合实际的应用来一点点的学习.废话不多说 ...

  8. ubuntu 修复 could not open file '/etc/apt/sources.list'

    问题描述:could not open file '/etc/apt/sources.list' 问题分析:软件源被清空了,也就是 /etc/apt/sources.list 被删除了 解决问题:1. ...

  9. 浅谈linux虚拟内存结构

    一个虚拟存储器系统要求硬件和软件之间紧密写作(mmu(内存管理单元,虚拟地址到物理地址的翻译),TLB块表(虚拟地址到物理地址index,虚拟寻址),l1,l2,l3高速缓存(物理单元数据)物理寻址) ...

  10. linux的nvme驱动参数调优

    nvme的设备,可以调优的参数比较少,相关的代码如下: blk_sysfs.c static struct queue_sysfs_entry queue_requests_entry = { .at ...