hdu 1724 Ellipse simpson积分
/*
hdu 1724 Ellipse simpson积分 求椭圆的部分面积
simpson积分法 http://zh.wikipedia.org/zh-tw/%E8%BE%9B%E6%99%AE%E6%A3%AE%E7%A7%AF%E5%88%86%E6%B3%95
*/
#include<stdio.h>
#include<math.h>
const double eps=1e-8;
inline double jue(double a)
{
return a>0?a:-a;
}
int dbcmp(double a)
{
if(a>eps)return 1;
if(a<(-eps)) return -1;
return 0;
}
template<typename T>
inline T sqr(T d){return d*d;}
double a,b;
inline double func(double x)
{
return 2*b*sqrt(1-sqr(x)/sqr(a));
}
double simpson(double l,double r)
{
return (func(l)+func(r)+4*func((l+r)/2))/6*(r-l);
}
double work(double l,double r)
{
double mid=(l+r)/2;
double ans=simpson(l,r);
if(dbcmp(ans-simpson(l,mid)-simpson(mid,r))==0)
{
return ans;
}else
{
return work(l,mid)+work(mid,r);
}
}
int main()
{
int n;
double l,r;
scanf("%d",&n);
while(n--)
{
scanf("%lf%lf%lf%lf",&a,&b,&l,&r);
double ret=work(l,r);
printf("%.3f\n",ret);
}
return 0;
}
hdu 1724 Ellipse simpson积分的更多相关文章
- HDU 1724 Ellipse ——Simpson积分
[题目分析] 一看题目,直接把椭圆积分起来就可以了嘛. 然后发现椭圆比较难积分,还是算了吧. 用Simpson积分硬上. 大概就是用二次函数去拟合面积. [代码] #include <cstdi ...
- HDU 1724 Ellipse [辛普森积分]
Ellipse Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu 1724 Ellipse——辛普森积分
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1724 #include<cstdio> #include<cstring> #in ...
- HDU 1724 Ellipse 【自适应Simpson积分】
Ellipse Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 1724 Ellipse (自适应辛普森积分)
题目链接:HDU 1724 Problem Description Math is important!! Many students failed in 2+2's mathematical tes ...
- 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 —— 自适应辛普森积分
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1724 函数都给出来了,可以用辛普森积分: 一开始 eps = 1e-8 TLE了,答案只要三位小数,那么 ...
- HDU Ellipse(simpson积分)
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
随机推荐
- linux执行文件命令
1.如果path中有你的程序所在的目录,那么直接执行filename即可 2.如果path中没有程序所在目录,那么进入目录./filename或者path/filename 比如 wj@ubuntu: ...
- (转)\r \r\n \t 的区别
小风吹雪 \r \r\n \t 的区别 http://www.360doc.com/content/12/0530/15/16538_214756101.shtml \n 软回车: 在Wi ...
- STL 之 vector 用法
一.头文件 #include<vector> 二.常用方法: // 在这个向量的尾部插入x的考贝,平均时间为常数,最坏时间为O(n): 1: void push_back(const T& ...
- Python3学习之一环境搭建
Windows 7 Python343下载 PTVS下载 Linux CentOS7 wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3 ...
- DoingOrder.aspx.cs缓存的使用方法
using System; using System.Web.UI; using System.Data; using System.Text; using BLL = SmartWaterSys.B ...
- 关于webApi302跳转的问题
之前会出现"服务器无法在已发送 HTTP 标头之后设置状态"的问题,本地调试不报错,但是上产线就会报错 解决的思路是: var response = Request.CreateR ...
- linux笔记2.19
压缩一般使用 tar -cvzf etcbackup.tar.gz /etc 寻找文件 locate(快速查找:新添加的得用updatedb更新后才能找到) find: find . -name ...
- javascript 正则匹配手机号码
<form class="form-horizontal" name="mobileform" style="padding:10px;&q ...
- 清除IE下链接虚线框
方法一:利用javascript的onfocus事件,实现如下: Html代码 <a href="http://www.www.baidu.com" onfocus=&qu ...
- 对PHP安全有帮助的一些函数
安全一直是一个在编程语言中非常值得去关注的方面.在任何一种成熟的编程语言中都有合适的办法来保证程序的安全性,在现代的 WEB 开发中 安全一直是一个在编程语言中非常值得去关注的方面.在任何一种成熟的编 ...