当前位置:网站首页>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;
}边栏推荐
- 国标GB28181协议EasyGBS级联宇视平台,保活消息出现403该如何处理?
- [geek challenge 2019] rce me 1
- 国标GB28181协议EasyGBS视频平台TCP主动模式拉流异常情况修复
- 手把手带你学会Odoo OWL组件开发(7):OWL项目实战使用
- postgis计算角度
- 初识-软件测试
- Electron official docs series: References
- Record a phpcms9.6.3 vulnerability to use the getshell to the intranet domain control
- Detailed explanation of C const: definition and use of C constant
- 四类线性相位 FIR滤波器设计 —— MATLAB源码全集
猜你喜欢

机器学习笔记 - 时间序列的季节性

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

Verilog中的系统任务(显示/打印类)--$display, $write,$strobe,$monitor

【网络是怎么连接的】第二章(中):一个网络包的发出

First knowledge - Software Testing

power designer - 自定义注释按钮
![P5733 [deep foundation 6. example 1] automatic correction](/img/34/081dbd805593a92a86c3081d6772e3.png)
P5733 [deep foundation 6. example 1] automatic correction

Power Designer - Custom Comment button

Processing 多面体变化
![[esp32-C3][RT-THREAD] 基于ESP32C3运行RT-THREAD bsp最小系统](/img/4a/503240b332e3279047c438f1d9845e.png)
[esp32-C3][RT-THREAD] 基于ESP32C3运行RT-THREAD bsp最小系统
随机推荐
710. random numbers in the blacklist
黑马笔记---常用API
710. 黑名单中的随机数
Tiger Dao VC products are officially launched, a powerful supplement to seektiger ecology
Redis learning - 03 transaction
Unit practice experiment 8 - using cmstudio to design microprogram instructions based on basic model machine (1)
PostGIS calculation angle
机组实践实验8——使用CMStudio设计基于基本模型机微程序指令(1)
机器学习笔记 - 时间序列的季节性
A must for programmers, an artifact utools that can improve your work efficiency n times
Deeply analyze the differences between dangbei box B3, Tencent Aurora 5S and Xiaomi box 4S
KVM 显卡透传 —— 筑梦之路
C structure: definition and example
不到40行代码手撸一个BlocProvider
老司机总结的12条 SQL 优化方案(非常实用)
Research and development practice of Kwai real-time data warehouse support system
. Net Maui performance improvement
LeetCode_栈_中等_150. 逆波兰表达式求值
Deep parsing MySQL binlog
心脏滴血漏洞(CVE-2014-0160)分析与防护