132. Code RAMs

Codeforces
IDCF10269132
Time10000ms
Memory256MB
Difficulty
English · Original
Formal · Original
You have a function $f (x)$, and you want to figure out how the area under $f (x)$ from 0 to $C$. In calculus, this value is called the $i n t e g r a l$ of $f (x)$. For some functions, taking its integral is relatively easy and uses a few simple rules. However, for many functions, it is impossible to find their integral exactly. However, you can make an approximation of the integral, and since you're writing a computer program, you can make a close approximation. One way to approximate the integral of a function is to use the Rectangular Approximation Method, or RAM. This method approximates the function $f (x)$ as $n$ rectangles, each having an equal width, and having varying $y$-values depending on the value of $f (x)$ at that point. As you can see, the example with $n$=4 ($f (x)$ was divided into four rectangles) was not perfect. However, as $n$ gets larger and larger, the approximations get more and more accurate. Formally, define the LRAM (Left Rectangular Approximation Method) approximation of the area under a function $f (x)$ from $0$ to $C$, using $n$ rectangles, as A, and the area of each rectangle as A1, A2 ... AN, as the following: A = $frac(A 1 * C, N)$ + $frac(A 2 * C, N)$ + $frac(A 3 * C, N)$+ ... + $frac(A N * C, N)$. The area of each rectangle can be calculated using the standard formula A = $l$ x $w$. The width of each subrectangle is equal to $frac(C, n)$ (because there are $n$ rectangles with a total width of $C$). The length of each subrectangle is equal to $f (frac(k * c, n))$, where $k$ represents the index of the rectangle, ranging from $0$ to $n -1$, inclusive. Since your answer must be a relatively close approximation, but your program should fit inside of the 10 second time limit (longer than usual for this problem), you should *set $N$ equal to 50000*. The only line of input contains a calculus equation. The equation will consist of the variable $x$, exponents, parentheses, and multiplication, division, addition, and subtraction operations. For example, $frac(x^2 -3, x^3 -x + 5)$ would be a valid input, but $c o s (x)$ would be not. Output a single decimal number: the area under $f (x)$ from $x$=$0$ to $x$=$C$. Your number should be close to the actual answer, but it doesn't have to be exact. *Using eval() or similar commands in your program is not allowed.* In the first sample case, $6. 663$ would be judged as correct, but $7$ would be judged as incorrect. ## Input The only line of input contains a calculus equation. The equation will consist of the variable $x$, exponents, parentheses, and multiplication, division, addition, and subtraction operations. For example, $frac(x^2 -3, x^3 -x + 5)$ would be a valid input, but $c o s (x)$ would be not. ## Output Output a single decimal number: the area under $f (x)$ from $x$=$0$ to $x$=$C$. Your number should be close to the actual answer, but it doesn't have to be exact. *Using eval() or similar commands in your program is not allowed.* [samples] ## Note In the first sample case, $6. 663$ would be judged as correct, but $7$ would be judged as incorrect.
**Definitions** Let $ f: \mathbb{R} \to \mathbb{R} $ be a rational function defined by a symbolic expression in $ x $, involving only $ +, -, \times, \div, \text{exponents}, \text{and parentheses} $. Let $ C \in \mathbb{R}^+ $ be the upper bound of integration. Let $ n = 50000 $. **Constraints** 1. $ f(x) $ is defined and continuous on $ [0, C] $. 2. $ C > 0 $. 3. The expression for $ f(x) $ contains no transcendental functions (e.g., $ \sin, \cos, \log $). **Objective** Compute the Left Rectangular Approximation Method (LRAM) estimate of $ \int_0^C f(x)\,dx $: $$ A = \sum_{k=0}^{n-1} f\left( \frac{k \cdot C}{n} \right) \cdot \frac{C}{n} $$
API Response (JSON)
{
  "problem": {
    "name": "132. Code RAMs",
    "description": {
      "content": "You have a function $f (x)$, and you want to figure out how the area under $f (x)$ from 0 to $C$.  In calculus, this value is called the $i n t e g r a l$ of $f (x)$. For some functions, taking its i",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 10000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269132"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You have a function $f (x)$, and you want to figure out how the area under $f (x)$ from 0 to $C$. \n\nIn calculus, this value is called the $i n t e g r a l$ of $f (x)$. For some functions, taking its i...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ f: \\mathbb{R} \\to \\mathbb{R} $ be a rational function defined by a symbolic expression in $ x $, involving only $ +, -, \\times, \\div, \\text{exponents}, \\text{and parentheses} $...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments