Ellipse

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

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

可以计算椭圆面积了哈哈
注意eps小一点
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const double eps=1e-; double a,b,l,r;
inline double F(double x){
return sqrt((a*a-x*x)/(a*a))*b;
}
inline double cal(double l,double r){
return (F(l)+F(r)+*F((l+r)/))*(r-l)/;
}
double Simpson(double l,double r,double now){
double mid=(l+r)/,p=cal(l,mid),q=cal(mid,r);
if(abs(now-p-q)<eps) return now;
else return Simpson(l,mid,p)+Simpson(mid,r,q);
} int main(int argc, const char * argv[]) {
int T;scanf("%d",&T);
while(T--){
scanf("%lf%lf%lf%lf",&a,&b,&l,&r);
l=max(l,-a);r=min(r,a);
printf("%.3f\n",*Simpson(l,r,cal(l,r)));
} return ;
}
 

HDU 1724 Ellipse [辛普森积分]的更多相关文章

  1. hdu 1724 Ellipse——辛普森积分

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1724 #include<cstdio> #include<cstring> #in ...

  2. hdu 1724 Ellipse simpson积分

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

  3. HDU 1724 Ellipse ——Simpson积分

    [题目分析] 一看题目,直接把椭圆积分起来就可以了嘛. 然后发现椭圆比较难积分,还是算了吧. 用Simpson积分硬上. 大概就是用二次函数去拟合面积. [代码] #include <cstdi ...

  4. HDU 1724 Ellipse (自适应辛普森积分)

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

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

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

  6. HDU 1724 Ellipse 【自适应Simpson积分】

    Ellipse Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  7. HDU 1724 Ellipse(数值积分の辛普森公式)

    Problem Description Math is important!! Many students failed in 2+2’s mathematical test, so let's AC ...

  8. HDU 1724 Ellipse 自适应simpson积分

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

  9. hdu 1724 : Ellipse 【Simpson积分】

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

随机推荐

  1. c++(循环单向链表)

    前面的博客中,我们曾经有一篇专门讲到单向链表的内容.那么今天讨论的链表和上次讨论的链表有什么不同呢?重点就在这个"循环"上面.有了循环,意味着我们可以从任何一个链表节点开始工作,可 ...

  2. [学习OpenCV攻略][008][Canny边缘检测]

    cvGetSize(输入图片) 得到输入图片的大小 cvCanny(输入图片,输出图片,lowThresh,highThresh,aperture) 把输入图片按设定光圈值进行Canny边缘检测,然后 ...

  3. web框架前言与学生数据库系统(附1.0源码)

    对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. import socket def f1(request): ""&quo ...

  4. JavaScript八张思维导图—基本语句

    JS基本概念 JS操作符 JS基本语句 JS数组用法 Date用法 JS字符串用法 JS编程风格 JS编程实践 不知不觉做前端已经五年多了,无论是从最初的jQuery还是现在火热的Angular,Vu ...

  5. dede list列表页和文章页分别使用if else

    标签: dede 2015-01-25 19:33 755人阅读 评论(0) 收藏 举报 分类: [ Dede ](20) 版权声明:本文为博主原创文章,未经博主允许不得转载. list列表页中使用i ...

  6. Android调试错误-No resource identifier found for attribute 'showAsAction'

    转载自:http://www.bubuko.com/infodetail-498830.html 1.问题描述: 24\YoumiAndroidSdk\demo\offers\res\menu\mai ...

  7. eclipse中git解决冲突

    摘录自http://blog.csdn.net/rosten/article/details/17068285 1. 工程->Team->同步 2.从远程pull至本地,就会出现如下内容 ...

  8. 【故障】MySQL主从同步故障-Slave_SQL_Running: No

    转自:http://www.linuxidc.com/Linux/2014-02/96945.htm 故障现象:进入slave服务器,运行:mysql> show slave status\G  ...

  9. 异步式I/O与实践式编程

    阻塞 线程在执行中如果遇到磁盘读写或网络通信(统称为I/O操作)通常要消耗很长时间 这时操作系统会剥夺这个线程的CPU控制权,使其暂停执行,同时将资源让给其他工作线程 异步I/O 非阻塞IO 针对所有 ...

  10. python异步加协程获取比特币市场信息

    目标 选取几个比特币交易量大的几个交易平台,查看对应的API,获取该市场下货币对的ticker和depth信息.我们从网站上选取4个交易平台:bitfinex.okex.binance.gdax.对应 ...