HDU 1724 Ellipse 【自适应Simpson积分】

时间:2023-01-18 17:54:48

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:

HDU 1724 Ellipse 【自适应Simpson积分】

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 HDU 1724 Ellipse 【自适应Simpson积分】, 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

题目大意:

  求椭圆HDU 1724 Ellipse 【自适应Simpson积分】被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 ;
}
/*
// //
*/

HDU 1724 Ellipse 【自适应Simpson积分】的更多相关文章

  1. HDU 1724 Ellipse 自适应simpson积分

    simpson公式是用于积分求解的比较简单的方法(有模板都简单…… 下面是simpson公式(很明显 这个公式的证明我并不会…… (盗图…… 因为一段函数基本不可能很规则 所以我们要用自适应积分的方法 ...

  2. HDU 1724 Ellipse &lpar;自适应辛普森积分&rpar;

    题目链接:HDU 1724 Problem Description Math is important!! Many students failed in 2+2's mathematical tes ...

  3. hdu 1724 Ellipse —— 自适应辛普森积分

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1724 函数都给出来了,可以用辛普森积分: 一开始 eps = 1e-8 TLE了,答案只要三位小数,那么 ...

  4. hdu 1724 &colon; Ellipse 【Simpson积分】

    题目链接 题意:给出椭圆方程中的a和b,再给出l.r,求l到r的积分的二倍. 输出时要求精度控制为保留到小数点后3位,如下代码中,eps设为1e-9 1e-8时均TLE,1e-4可以AC,1e-3会W ...

  5. HDU - 1724 Ellipse 自适应辛普森模板

    OJ 题解传送门 //Achen #include<algorithm> #include<iostream> #include<cstring> #include ...

  6. hdu 1724 Ellipse simpson积分

    /* hdu 1724 Ellipse simpson积分 求椭圆的部分面积 simpson积分法 http://zh.wikipedia.org/zh-tw/%E8%BE%9B%E6%99%AE%E ...

  7. 自适应Simpson积分

    自适应Simpson积分 作用 如标题所示,这玩意就是当你不会微积分的时候来求积分的. 总所周知,积分的定义就是函数的某一段与坐标轴之间的面积. 那么,自适应Simpson积分就是一种可以再某些精度下 ...

  8. 【bzoj1502】&lbrack;NOI2005&rsqb;月下柠檬树 自适应Simpson积分

    题目描述 李哲非常非常喜欢柠檬树,特别是在静静的夜晚,当天空中有一弯明月温柔地照亮地面上的景物时,他必会悠闲地坐在他亲手植下的那棵柠檬树旁,独自思索着人生的哲理.李哲是一个喜爱思考的孩子,当他看到在月 ...

  9. CSU 1806 Toll 自适应simpson积分&plus;最短路

    分析:根据这个题学了一发自适应simpson积分(原来积分还可以这么求),然后就是套模板了 学习自适应simpson积分:http://blog.csdn.net/greatwall1995/arti ...

随机推荐

  1. 分享一个UI与业务逻辑分层的框架&lpar;二&rpar;

    序言 第一篇讲解了UI与业务逻辑分层的框架(UIMediator)的使用.本篇将说明该框架的原理及代码实现. 整体结构 UI与后台类绑定主要分为UI输入->后台属性,后台属性-UI更新两部分,为 ...

  2. Odoo10尝鲜: 退货

    Odoo sale / purchase 在 v9 改进之后, 开立发票的入口 不再像之前的版本,有多个来源,例如 订单 交货单 记工单 分析分录     现在只有一个入口,只需要在 订单上开票,这样 ...

  3. 【Unity3D】【NGUI】怎样动态给EventDelegate加入參数

    NGUI版本号:3.6.8 注意:參数必须是公共成员变量.不能是栈上的.或者私有的(就是暂时在函数里面定义的或者是函数的參数都不行) using UnityEngine; using System.C ...

  4. five kinds of IPC methods

    Shared memory permits processes to communicate by simply reading and writing to a specified memory l ...

  5. Html&period;Partial和Html&period; RenderPartial用法

    Html.Partial和Html. RenderPartial用法 Html.partial和RenderPartial的用法与区别Html.partial和RenderPartial都是输出htm ...

  6. Java NIO之通道

    一.前言 前面学习了缓冲区的相关知识点,接下来学习通道. 二.通道 2.1 层次结构图 对于通道的类层次结构如下图所示. 其中,Channel是所有类的父类,其定义了通道的基本操作.从 Channel ...

  7. 前端面试题:css相关面试题

    CSS 选择器中,元素选择器和类选择器的区别是什么? 元素选择器是最常见的 CSS 选择器,即,文档的元素就是最基本的选择器.选择器通常是某个 HTML 元素,比如 <p>.<h1& ...

  8. Java中的BlockingQueue队列

    BlockingQueue位于JDK5新增的concurrent包中,它很好地解决了多线程中,如何高效安全地“传输”数据的问题.通过这些高效并且线程安全的队列类,为我们快速搭建高质量的多线程程序带来极 ...

  9. AAPT err&lpar;Facade for&rpar;&colon; libpng error&colon; Not a PNG file 错误解决

    在导入项目到Android studio后,若编译出现“AAPT err(Facade for): libpng error: Not a PNG file”错误. 该错误表示项目中的drawable ...

  10. 2017-2018-2 20155315《网络对抗技术》Exp3:免杀原理与实践

    实验目的 通过本部分内容的学习,认识到杀软局限性,提高在工作生活中对于恶意软件防范能力. 教程 实验内容 使用msf编码器,msfvenom,veil-evasion,shellcode编程等免杀工具 ...