HDU 1724 Ellipse 【自适应Simpson积分】
Ellipse
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1977 Accepted Submission(s): 832Problem DescriptionMath 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 )
InputInput 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).
OutputFor each case, output one line containing a float, the area of the intersection, accurate to three decimals after the decimal point.Sample Input2
2 1 -2 2
2 1 0 2Sample Output6.283
3.142Author威士忌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 ;
}
/*
//
//
*/
HDU 1724 Ellipse 【自适应Simpson积分】的更多相关文章
- HDU 1724 Ellipse 自适应simpson积分
simpson公式是用于积分求解的比较简单的方法(有模板都简单…… 下面是simpson公式(很明显 这个公式的证明我并不会…… (盗图…… 因为一段函数基本不可能很规则 所以我们要用自适应积分的方法 ...
- HDU 1724 Ellipse (自适应辛普森积分)
题目链接:HDU 1724 Problem Description Math is important!! Many students failed in 2+2's mathematical tes ...
- hdu 1724 Ellipse —— 自适应辛普森积分
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1724 函数都给出来了,可以用辛普森积分: 一开始 eps = 1e-8 TLE了,答案只要三位小数,那么 ...
- hdu 1724 : Ellipse 【Simpson积分】
题目链接 题意:给出椭圆方程中的a和b,再给出l.r,求l到r的积分的二倍. 输出时要求精度控制为保留到小数点后3位,如下代码中,eps设为1e-9 1e-8时均TLE,1e-4可以AC,1e-3会W ...
- HDU - 1724 Ellipse 自适应辛普森模板
OJ 题解传送门 //Achen #include<algorithm> #include<iostream> #include<cstring> #include ...
- hdu 1724 Ellipse simpson积分
/* hdu 1724 Ellipse simpson积分 求椭圆的部分面积 simpson积分法 http://zh.wikipedia.org/zh-tw/%E8%BE%9B%E6%99%AE%E ...
- 自适应Simpson积分
自适应Simpson积分 作用 如标题所示,这玩意就是当你不会微积分的时候来求积分的. 总所周知,积分的定义就是函数的某一段与坐标轴之间的面积. 那么,自适应Simpson积分就是一种可以再某些精度下 ...
- 【bzoj1502】[NOI2005]月下柠檬树 自适应Simpson积分
题目描述 李哲非常非常喜欢柠檬树,特别是在静静的夜晚,当天空中有一弯明月温柔地照亮地面上的景物时,他必会悠闲地坐在他亲手植下的那棵柠檬树旁,独自思索着人生的哲理.李哲是一个喜爱思考的孩子,当他看到在月 ...
- CSU 1806 Toll 自适应simpson积分+最短路
分析:根据这个题学了一发自适应simpson积分(原来积分还可以这么求),然后就是套模板了 学习自适应simpson积分:http://blog.csdn.net/greatwall1995/arti ...
随机推荐
- ProtoBuf - Arena
1.概述 最近看 Protocal Buffer 的源码,初次见到这个库源自陈硕的 muduo ,便打算看一看,在此做一下记录.官网文档不能访问,只能凭借代码的自己理解,查看的源码版本为 3.6.0. ...
- glibc库函数,系统调用API
glibc封装了大部分系统API,我们一般都是使用glibc封装的接口进行系统调用,碰到一些没有封装的接口,可以通过这个 函数syscall 进行系统调用. /* Invoke `system c ...
- C#基础学习(一)
---恢复内容开始--- 1.最近被安排去做C#开发,然后开始一连串的看文档·看视屏,发现学C#给自己补了很多基础,C#每个函数变量什么都要先声名,而python可以直接定义: 一.数据类型 1.整数 ...
- MySQL-----改
改 **修改用户名** rename user 'username'@'IP address' to 'new username'@'IP address'; **修改密码** set passwor ...
- android 如何从activity跳转到另一个activity下指定的fragment
思路: 跳转到目标fragment所在的activity,并传递一个flag,来确定要到哪个fragment,根据该flag判断后,跳转到指定的fragment即可. 代码: 当前界面: intent ...
- LeetCode(48)Rotate Image
题目 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise ...
- GitHub & puppeteer & Chinese character & bug
GitHub & puppeteer & Chinese character & bug https://github.com/GoogleChrome/puppeteer/b ...
- hihoCoder#1077 RMQ问题再临-线段树
原题地址 终于做到线段树的题了,因为建树.更新.查询都是递归操作,所以其实挺好写的. 用数组存的树,记得MAX_NODE开成两倍叶节点数大小,否则RE啊..不要问我是怎么知道的. 代码: #inclu ...
- CSU 1554 SG Value (集合类的学习)
题目大意: 2种操作 1 a:往集合中添加一个元素a 2: 询问这个集合中的元素任意组合相加所不能得到的最小数的值 这道题总是不断地去找当前所能处的最小值能否被当前的最小值加上其前部的一堆可抵达数到达 ...
- POJ3107 树的重心
题解:只不过如果有求多个点,输出所有方案. #include<cstring> #include<cmath> #include<iostream> #includ ...