Hdoj 1724 Ellipse Adaptive Simpson

Source: Internet
Author: User


Adaptive Simpson

EllipseTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1268 Accepted Submission (s): 493


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

/* ***********************************************author:ckbosscreated time:2014 December 27 Saturday 22:46 38 seconds file Name : hdoj1724.cpp************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map>using namespace std;double a , B,l,r;double F (double x) {return b*sqrt ((1-x/a) * (1+x/a));} 3-points simpsondouble Simpson (double a,double b) {double c= (a+b)/2;return (F (a) +4*f (c) +f (b)) * (B-A)/6.;} Double ASR (double a,double b,double eps,double a) {double c= (a+b)/2;double L=simpson (a,c), R=simpson (c,b); if (Fabs (l+r-a ) <=15*eps) return l+r+ (l+r-a)/15.0;return ASR (a,c,eps/2,l) +ASR (c,b,eps/2,r);} Double ASR (double a,double b,double EPS) {return ASR (A,b,eps,simpson (b));}    int main () {//freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout); int t_t;scanf("%d", &t_t), while (t_t--) {scanf ("%lf%lf%lf%lf", &a,&b,&l,&r);p rintf ("%.3lf\n", 2.*asr (L,r,        1e-6));} return 0;}




Hdoj 1724 Ellipse Adaptive Simpson

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.