No.1009 How to Find the Area
Problem Statement
You are given integers $a,b \ (a\le b)$.
Let $f(x)=(x-a)(x-b)$. Find the area of the region enclosed by the parabola $y=f(x)$ and the $x$-axis on the 2D plane.
The answer may be a decimal; an absolute or relative error of up to $10^{-4}$ is allowed.
Hint
Finding the area of a region enclosed by curves on the 2D plane normally requires knowledge of integration.
However, even such a problem does not require complicated knowledge if you can approximate well.
For example, one alternative to integration is the method of piecewise quadrature, which divides the interval $[a,b]$ into $N$ equal intervals, approximates the area over each resulting interval $[X_k,X_{k+1}] (k=1,2,3, \dots , N)$ by the area of the rectangle
$\frac{b-a}{N} \times \vert f(X_k) \vert$
and takes the sum. (The error of piecewise quadrature is generally $O(\frac{1}{N})$.)
There are also methods whose error converges faster than piecewise quadrature, such as the trapezoidal rule, which divides the interval in the same way and approximates the area by trapezoids.
Illustration of piecewise quadrature
Input
$a\ b$
All input values are integers.
$ -10 \le a \le b \le 10 $
Output
Output the area of the region enclosed by the parabola $y=f(x)$ and the $x$-axis.
Print a newline at the end.
Sample
Sample 1
Input
-3 3
Output
36
The area of the region enclosed by the $x$-axis and the parabola $y=(x+3)(x-3)$ is 36.
Sample 2
Input
0 0
Output
0
The parabola may be tangent to the $x$-axis. In this case, output 0.
Sample 3
Input
2 7
Output
20.8333333
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
otamay6
neterukun