QOJ.ac

QOJ

実行時間制限: 5.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#9654. 循环函数

統計

Fish 正在学习函数!他有一个线性函数 $f(x) = Ax + B$ 和 $N$ 个数 $x_1, x_2, \dots, x_N$。现在他很好奇对于每一个函数 $g(x)$:

$$ \left\{ \begin{aligned} g_1(x) &= c_1x + d_1 \\ g_2(x) &= c_2x + d_2 \\ &\vdots \\ g_M(x) &= c_Mx + d_M \end{aligned} \right\} $$

如何计算 $f(g(x))$ 和 $g(f(x))$ 之间的差异。 聪明的 Fish 很快想出了一个函数 $D(x) = |f(g(x)) - x| + |g(f(x)) - x|$,并使用它在 $x_1, x_2, \dots, x_N$ 上的求和作为差异。 你能立刻告诉他所有的差异吗?

输入格式

输入的第一行包含一个整数 $T$,表示测试用例的数量。 对于每个测试用例: 第一行包含两个整数 $N, M$ 以及两个实数 $A, B$,表示给定的函数 $f(x) = Ax + B$。 第二行包含 $N$ 个实数 $x_1, x_2, \dots, x_N$。 接下来有 $M$ 行,每行包含两个实数 $c_i, d_i$,表示上述函数 $g_i(x) = c_ix + d_i$。 同一行中的所有数字均由一个空格分隔。

输出格式

对于每个测试用例,第一行输出 Case x:,其中 $x$ 是从 1 开始的测试用例编号。 接下来输出 $M$ 行,第 $i$ 行包含一个实数,表示给定函数 $g_i(x)$ 的差异。 如果你的答案的绝对误差不超过 $10^{-6}$,则被视为正确。

样例

输入 1

2
3 2 2.0 3.0
1.0 2.0 3.0
0.4 -2.0
0.6 -5.0
3 2 2.5 2.0
1.0 2.0 3.0
0.4 -2.0
0.6 -5.0

输出 1

Case 1:
7.800000
28.200000
Case 2:
12.600000
36.900000

说明

$1 \le T \le 100$ $1 \le N, M \le 10^5$ $-100 \le A, B, x_i, c_i, d_i \le 100$ 对于 90% 的测试用例:$\max(N, M) \le 1000$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.