Matching the Integral with a Riemann Sum
Time limit1sMemory limit512 MB
Given a polynomial, an interval [a,b], and N subintervals, find epsilon in [0, dx] where the Riemann sum equals the exact integral, or print -1.
- Level
Medium6 of 10
- Topics
- Math, Binary search, Implementation, Brute force
- Solved
- No attempts yet
Problem
The integral of a function can be approximated as follows.
Mingyu was happily working through integrals at boot camp when he wondered whether a well-chosen could make this approximation equal the exact integral. Checking that needs decimal arithmetic, which is hard to do by hand, so he asked you to write a program for it.
In this problem, is a polynomial.
Input
The first line contains a positive integer (), the degree of the polynomial.
The second line contains the integer coefficients , listed from the highest-degree term down to the constant term (, ).
The third line contains two integers and , the start and end of the integration interval, and the number of subintervals (, ).
Output
Print on one line the value of that makes the Riemann sum approximation equal the exact integral, rounded to exactly six digits after the decimal point. For example, if the answer is , print 0.250000.
For the given input, at most one satisfies the condition. If no such value exists, print -1.
Hint
The integral of a polynomial term is computed as follows.