Ellipse

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

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
威士忌
 
Source

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=1724

题目大意:

  求椭圆被x=l,x=r两条线所围区域面积。

题目思路:

  【自适应Simpson积分】

  首先易得上半部分面积积分公式为sqrt(b2(1-x2/a2))

  接下来就是套用自适应Simpson积分即可。eps一开始设为1e-4就行。

  一道模板题。

 /****************************************************

     Author : Coolxxx
Copyright 2017 by Coolxxx. All rights reserved.
BLOG : http://blog.csdn.net/u010568270 ****************************************************/
#include<bits/stdc++.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define mem(a,b) memset(a,b,sizeof(a))
const double eps=1e-;
const int J=;
const int mod=;
const int MAX=0x7f7f7f7f;
const double PI=3.14159265358979323;
const int N=;
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
double a,b;
double F(double x)//原函数f(x)
{
return sqrt(b*b*(-x*x/(a*a)));
}
double simpson(double a,double b)//求simpson公式S(a,b)
{
double mid=(a+b)/;
return (b-a)/*(F(a)+*F(mid)+F(b));
}
double simpson(double l,double r,double eps,double A)//自适应simpson积分过程
{
double mid=(l+r)/;
double L=simpson(l,mid);
double R=simpson(mid,r);
if(abs(L+R-A)<=*eps)return L+R+(L+R-A)/15.0;//eps为精度需求
return simpson(l,mid,eps/,L)+simpson(mid,r,eps/,R);
}
double simpson(double l,double r,double eps)//自适应simpson积分
{
return simpson(l,r,eps,simpson(l,r));
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
double x,y,z;
// for(scanf("%d",&cass);cass;cass--)
for(scanf("%d",&cas),cass=;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d",&n))
{
scanf("%lf%lf%lf%lf",&a,&b,&x,&y);
printf("%.3lf\n",simpson(x,y,1e-)*);
}
return ;
}
/*
// //
*/

最新文章

  1. 在WPF中使用依赖注入的方式创建视图
  2. expdp ORA-31693 ORA-31617 ORA-19505 ORA-27037
  3. POJ 1743 后缀数组
  4. OC基础—多态(超级简单)
  5. if条件里比较浮点数
  6. ServiceStack.Redis之IRedisClient&lt;第三篇&gt;
  7. poj 3311 tsp入门
  8. Part 14 Mathematical functions in sql server
  9. Ant构建与部署Java项目---入门
  10. H-JATG:NAND_FLASH的参数设置
  11. shrio登录验证
  12. WEB服务器:Apache、Tomcat、JBoss、WebLogic、Websphere、IIS的区别与关系
  13. 聊聊React高阶组件(Higher-Order Components)
  14. 不能ssh连接ubuntu linux 服务器 secureCRT不能ssh连接服务器 不能远程ssh连接虚拟机的ubuntu linux
  15. poj3280 Cheapest Palindrome(回文串区间dp)
  16. QT使用MSVC编译器输出中文乱码问题解决方法
  17. 和我一起打造个简单搜索之ElasticSearch入门
  18. css3新增的content 的用法:
  19. Hyperledger Fabric 实战(十二): Fabric 源码本地调试
  20. 20165330 2017-2018-2 《Java程序设计》第1周学习总结

热门文章

  1. scrollfix.js插件:滚动固定在某个位置
  2. HDU - 2058 The sum problem(思路题)
  3. IDEA修改背景图片和主题代码风格
  4. Delphi 正则表达式 TPerlRegEx 类
  5. jQuery对table排序
  6. django-3 admin开启后台配置并展示表内容
  7. HttpURLConnection绕过HTTPS的SSL验证
  8. Windows学习总结(11)——Windows批处理命令编写代码及小程序简介
  9. jQuery_计算器实例
  10. HDU 4960 (水dp)