EllipseTime
limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1358 Accepted Submission (s): 532
Problem Descriptionmath is important!! Many students failed in + 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 at Point O. The l,r lines would be vertical through the x-axis. The problem is calculating, the blue intersection area. But calculating the intersection area was dull, so I had 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 would 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 th e decimal point.
Sample Input
22 1-2 22 1 0 2
Sample Output
6.2833.142
Author whisky
SOURCEHZIEE Programming Contest
Recommendlcy
Simpson points.
The elliptic formula in this problem is x/a^2+y/b^2=1 so f (x) =2*b*sqrt (1-x^2/a^2)
#include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include < Cstdio> #define EPS 1e-9using namespace std;double a,b,l,r;double F (double x) {return 2*b*sqrt ((double) 1-x*x/(A*a));} Double Calc (double l,double r) {double m= (l+r)/(double) 2;return (r-l) * (F (L) + (double) 4*f (m) +f (R))/(double) 6;} Double Simpson (double l,double r) {double m= (l+r)/(double) 2;double Fl=calc (l,m), Fr=calc (m,r); if (Fabs (FL+FR-CALC) ) <eps) return Fl+fr;return Simpson (l,m) +simpson (m,r);} int main () { int t;scanf ("%d", &t), while (t--) {scanf ("%lf%lf%lf%lf", &a,&b,&l,&r);p rintf ("%. 3lf\n ", Simpson (L,r));} return 0;}
WA is due to lack of precision.
"HDU 1724" Ellipse