当前位置:网站首页>HDU1724[辛普森公式求积分]Ellipse
HDU1724[辛普森公式求积分]Ellipse
2022-06-26 12:39:00 【YJEthan】
Description
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
Output
Sample Input
2
2 1 -2 2
2 1 0 2
Sample Output
6.283
3.142
分析:用辛普森公式求积分

简单模板题直接套
#include<stdio.h>
#include<math.h>
#define eps 1e-9
double a,b,l,r;
double F(double x)
{
return 2*b*sqrt(1.0-x*x/(a*a));
}
double cal(double l,double r)
{
return (r-l)/6.0*(F(r)+4.0*F((r+l)/2.0)+F(l));
}
double simpson(double l,double r)
{
double m=(l+r)/2.0;
double fl=cal(l,m),fr=cal(m,r);
if(fabs(fl+fr-cal(l,r))<eps) return fr+fl;
else return simpson(l,m)+simpson(m,r);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf%lf",&a,&b,&l,&r);
printf("%.3lf\n",simpson(l,r));
}
return 0;
}边栏推荐
- Goto statement to realize shutdown applet
- RSS rendering of solo blog system failed
- C# 结构体:定义、示例
- 倍福PLC通过程序获取系统时间、本地时间、当前时区以及系统时间时区转换
- 由错误<note: candidate expects 1 argument, 0 provided>引发的思考
- 不到40行代码手撸一个BlocProvider
- LeetCode_栈_中等_150. 逆波兰表达式求值
- Biff TwinCAT can quickly detect the physical connection and EtherCAT network through emergency scan
- Redis learning - 02 common data types, operation commands and expiration time
- 国标GB28181协议EasyGBS视频平台TCP主动模式拉流异常情况修复
猜你喜欢

轻流完成与「DaoCloud Enterprise 云原生应用云平台」兼容性认证

【网络是怎么连接的】第二章(下):一个网络包的接收

This function has none of deterministic, no SQL solution

Echart堆叠柱状图:色块之间添加白色间距效果设置

倍福PLC实现绝对值编码器原点断电保持---bias的使用

NoSQL mongodb - 01 introduction to NoSQL and mongodb

软件测试 - 概念篇

【网络是怎么连接的】第一章:浏览器生成消息
![P5733 [deep foundation 6. example 1] automatic correction](/img/34/081dbd805593a92a86c3081d6772e3.png)
P5733 [deep foundation 6. example 1] automatic correction

processsing 函数random
随机推荐
sqlalchemy event listen Automatic generate CRUD excel
软件测试 - 基础篇
Accumulation of interview questions
EasyGBS如何解决对讲功能使用异常?
手把手带你学会Odoo OWL组件开发(7):OWL项目实战使用
. Net Maui performance improvement
Redis learning - 03 transaction
【shell】生成指定日期之间的字符串
RSS rendering of solo blog system failed
el-form-item 包含两个input, 校验这两个input
NoSQL mongodb - 01 introduction to NoSQL and mongodb
Research and development practice of Kwai real-time data warehouse support system
中科软外包一面
NoSQL mongodb - 04 mongodb database and web service combination case
P5733 【深基6.例1】自动修正
tauri vs electron
Solution of Splunk iowait alarm
Tiger Dao VC products are officially launched, a powerful supplement to seektiger ecology
Photoshop 2022 23.4.1增加了哪些功能?有知道的吗
PostGIS geographic function