hdu 1724 Ellipse(Simpson积分法)
来源:互联网 发布:好看的恐怖电影知乎 编辑:程序博客网 时间:2024/05/22 06:32
Ellipse
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1152 Accepted Submission(s): 435
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:
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
22 1 -2 22 1 0 2
Sample Output
6.2833.142Simpson积分法:http://zh.wikipedia.org/wiki/%E8%BE%9B%E6%99%AE%E6%A3%AE%E7%A9%8D%E5%88%86%E6%B3%95AC代码:#include <iostream>#include <cmath>#include <cstdlib>#include <cstring>#include <cstdio>#include <queue>#include <ctime>#include <algorithm>#define ll long longusing namespace std;const int INF = 1e9;const int maxn = 505;const double eps = 1e-8;double a, b;double F(double x){ return 2.0 * b * sqrt(1.0 - x * x / (a * a));}double simpson(double l, double r){ double mid = (l + r) / 2.0; return (r - l) * (F(l) + 4.0 * F(mid) + F(r)) / 6.0;}double work(double l, double r, double sum){ double mid = (l + r) / 2.0; double ls = simpson(l, mid); double rs = simpson(mid, r); if(abs(ls + rs - sum) <= eps) return sum; return work(l, mid, ls) + work(mid, r, rs);}int main(){ int t; double l, r; scanf("%d", &t); while(t--) { scanf("%lf%lf%lf%lf", &a, &b, &l, &r); double ans = work(l, r, simpson(l, r)); printf("%.3f\n", ans); } return 0;}
0 0
- hdu 1724 Ellipse(Simpson积分法)
- hdu 1724 Ellipse(simpson求积分)
- HDU-#1724 Ellipse(自适应Simpson法+数值积分)
- hdu 1724 Ellipse simpson积分
- HDU 1724 Ellipse (simpson公式,求积分)
- HDU 1724 Ellipse 【自适应Simpson积分】
- hdu 1724 Ellipse(自适应Simpson积分) (模板)
- 【自适应Simpson积分】hdu 1724 Ellipse
- HDOJ 1724 Ellipse(自适应simpson积分)
- hdoj-1724 Ellipse(自适应Simpson积分)
- 【HDU1724】Ellipse-自适应Simpson积分法
- hdu 1724(Simpson积分)
- HDU 1724 Ellipse 自适应simpson函数模板题(二)
- Hdu 1724 Ellipse (自适应辛普森积分法)
- HDU 1724 (simpson积分)
- HDU 1724 Ellipse 自适应辛普森积分
- HDU 1724 Ellipse (自适应辛普森积分)
- HDOJ 1724 Ellipse 自适应Simpson
- OpenGLES demo - 15. 阴影贴图 Shadow Map 之点光源
- poj 3400 Dropping the stones
- memset函数使用详解
- Cocos2d-x使用Luajit将Lua脚本编译为bytecode,从而实现加密
- Java多线程解决生产者和消费者问题(面向对象)
- hdu 1724 Ellipse(Simpson积分法)
- c语言左移右移
- 设计模式实现(十八)---桥接模式(Bridge)
- Android短信的备份
- navicat 结合快捷键 非常好用
- lazy懒加载(延迟加载)UITableView
- VB程序逆向反汇编常见的函数
- hdu 1048 The Hardest Problem Ever
- find sed sort wc 20140804