HDU Ellipse(simpson积分)
2018-06-27 10:06:53来源:未知 阅读 ()
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2677 Accepted Submission(s):
1208
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 )
#include<cstdio> #include<cmath> int N; double a, b, L, R; double f(double x) { return 2 * b * sqrt(1.0 - (x * x) / (a * a)); } double sim(double l, double r) { return (f(l) + f(r) + 4.0 * f((l + r) / 2.0)) * (r - l) / 6.0; } double asr(double l, double r, double eps, double ans) { double mid = (l + r) / 2; double la = sim(l, mid), ra = sim(mid, r); if(fabs(la + ra - ans) < eps) return la + ra; return asr(l, mid, eps / 2, sim(l, mid)) + asr(mid, r, eps / 2, sim(mid, r)); } main() { scanf("%d", &N); while(N--) { scanf("%lf %lf %lf %lf", &a, &b, &L, &R); printf("%.3lf\n", asr(L, R, 1e-5, sim(L, R))); } }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- hdu1062 text reverse 2020-01-27
- hdu4841 2020-01-26
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash