C. Cycle Function

Codeforces
IDCF10282C
Time5000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Fish is learning functions! He has a linear function $f (x) = A x + B$ and $N$ numbers $x_1, x_2, \\\\cdots, x_N$. Now he is curious about for each function $g (x)$ in how to calculate the difference between $f (g (x))$ and $g (f (x))$. As smart as Fish is, he soon comes up with a function $D (x) = | f (g (x)) -x | + | g (f (x)) -x |$ and uses the sum over $x_1, x_2, \\\\cdots, x_N$ as the difference. Can you tell him all the differences immediately? The first line of input contains an integer $T$, representing the number of test cases. Then for each test case: The first line contains two integers $N$, $M$ as mentioned above and then two real numbers $A$, $B$ indicating the given function $f (x) = A x + B$. The second line contains $N$ real numbers $x_1, x_2, \\\\cdots, x_N$. Then $M$ lines follow, each line containing two real numbers $c_i$, $d_i$ indicating a function $g_i (x) = c_i x + d_i$ mentioned above. All numbers in the same line are separated by one space. For each test case, you should output *Case $x$:* in the first line, where x indicates the case number starting from 1. Then $M$ lines follow, the $i$-th line of which contains a real number representing the difference for given function $g_i (x)$. Your answers will be considered correct if its absolute error does not exceed $10^(-6)$. $1 <= T <= 100$ $1 <= N, M <= 10^5$ $-100 <= A, B, x_i, c_i, d_i <= 100$ For $90 %$ test cases: $max (N, M) <= 1000$ ## Input The first line of input contains an integer $T$, representing the number of test cases.Then for each test case:The first line contains two integers $N$, $M$ as mentioned above and then two real numbers $A$, $B$ indicating the given function $f (x) = A x + B$.The second line contains $N$ real numbers $x_1, x_2, \\\\cdots, x_N$.Then $M$ lines follow, each line containing two real numbers $c_i$, $d_i$ indicating a function $g_i (x) = c_i x + d_i$ mentioned above.All numbers in the same line are separated by one space. ## Output For each test case, you should output *Case $x$:* in the first line, where x indicates the case number starting from 1.Then $M$ lines follow, the $i$-th line of which contains a real number representing the difference for given function $g_i (x)$.Your answers will be considered correct if its absolute error does not exceed $10^(-6)$. [samples] ## Note $1 <= T <= 100$$1 <= N, M <= 10^5$$-100 <= A, B, x_i, c_i, d_i <= 100$For $90 %$ test cases: $max (N, M) <= 1000$
Let $ n \in \mathbb{Z} $, $ 1 \leq n \leq 10^9 $. **Objective**: Find the minimum number of 1s to add in binary representation of $ n $, where each addition corresponds to a manual react, and doubling corresponds to left-shift (bit shift left). The minimum number of manual reacts is equal to the number of 1s in the binary representation of $ n $. $$ \boxed{\text{popcount}(n)} $$
API Response (JSON)
{
  "problem": {
    "name": "C. Cycle Function",
    "description": {
      "content": "Fish is learning functions! He has a linear function $f (x) = A x + B$ and $N$ numbers $x_1, x_2, \\\\\\\\cdots, x_N$. Now he is curious about for each function $g (x)$ in  how to calculate the differenc",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 5000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10282C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Fish is learning functions! He has a linear function $f (x) = A x + B$ and $N$ numbers $x_1, x_2, \\\\\\\\cdots, x_N$. Now he is curious about for each function $g (x)$ in \n\nhow to calculate the differenc...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ n \\in \\mathbb{Z} $, $ 1 \\leq n \\leq 10^9 $.\n\n**Objective**: Find the minimum number of 1s to add in binary representation of $ n $, where each addition corresponds to a manual react, and doublin...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments