当前位置:网站首页>Hdu1724[Simpson formula for integral]ellipse
Hdu1724[Simpson formula for integral]ellipse
2022-06-26 13:11: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
analysis : Use Simpson's formula to find the integral

Simple template questions set directly
#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;
}边栏推荐
- Vivado error code [drc pdcn-2721] resolution
- H - Sumsets POJ 2229
- Processing random generation line animation
- Basic principle and application routine of Beifu PLC rotary cutting
- 倍福PLC基于CX5130实现数据的断电保持
- PostGIS geographic function
- G - Cow Bowling
- Record a phpcms9.6.3 vulnerability to use the getshell to the intranet domain control
- 利用scrapy爬取句子迷网站优美句子存储到本地(喜欢摘抄的人有福了!)
- May product upgrade observation station
猜你喜欢
随机推荐
J - Wooden Sticks poj 1065
UVa11582 [快速幂]Colossal Fibonacci Numbers!
Opencv high speed download
C - Common Subsequence
Use the script to crawl the beautiful sentences of the sentence fan website and store them locally (blessed are those who like to excerpt!)
Guacamole installation
Biff TwinCAT can quickly detect the physical connection and EtherCAT network through emergency scan
Sinotech software outsourcing
复制多个excel然后命名不同的名字
Appearance mode (facade)
QT .pri 的建立与使用
tauri vs electron
Arcpy——InsertLayer()函数的使用:掺入图层到地图文档里
B - Bridging signals
Bridge mode
利用scrapy爬取句子迷网站优美句子存储到本地(喜欢摘抄的人有福了!)
Deep parsing MySQL binlog
Electron official docs series: Get Started
倍福PLC基于CX5130实现数据的断电保持
倍福PLC基于NT_Shutdown实现控制器自动关机重启
![[BSidesCF 2019]Kookie 1](/img/22/585d081668e67b8389a1b90aaebe9d.png)








