HDU1724 Ellipse

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 ) 

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 Input

2
2 1 -2 2
2 1 0 2

Sample Output

6.283
3.142

几何

simpson积分强行搞

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cmath>
 6 using namespace std;
 7 const double eps=1e-9;
 8 const int mxn=100010;
 9 int read(){
10     int x=0,f=1;char ch=getchar();
11     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
12     while(ch>='0' && ch<='9'){x=x*10-'0'+ch;ch=getchar();}
13     return x*f;
14 }
15 int a,b;
16 inline double f(double x){
17     return b*sqrt((double)1-(x*x/(double)a/a));
18 }
19 inline double sim(double l,double r){
20     return (r-l)/6*(f(l)+4*f((l+r)/2)+f(r));
21 }
22 double solve(double l,double r){
23     double mid=(l+r)/2;
24     double res=sim(l,r);
25 //    printf("l:%.3f  r:%.3f  res:%.3f
",l,r,res);
26     if(fabs(sim(l,mid)+sim(mid,r)-res)<=eps)return res;
27     return solve(l,mid)+solve(mid,r);
28 }
29 int main(){
30     int T=read();
31     double l,r;
32     while(T--){
33         a=read();b=read();
34         l=read();r=read();
35         double ans=solve(l,r);
36         printf("%.3f
",2*ans);
37     }
38     return 0;
39 }
原文地址:https://www.cnblogs.com/SilverNebula/p/6351794.html