QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#700. 音高表现

Statistics

在最近一次复活节卡拉 OK 聚会的灾难性表现后,你决定提升自己的歌唱水平。为了衡量你的进步,你需要计算你的歌声在音高和节奏上与你试图演唱的目标旋律之间的差异。

我们将旋律简化建模为一个分段常数函数 $f$,其中在时间 $x$ 时,旋律的音高为 $f(x)$。换句话说,从时间 $0$ 到某个时间 $x_1$,$f(x)$ 为某个常数值 $y_1$,然后在时间 $x_1$ 时它变为另一个值 $y_2$,并保持该值直到某个时间 $x_2 > x_1$,依此类推。

另一方面,你的歌声波动较大,通常无法在任何时间段内保持精确的恒定音高,有时会突然变成令人不快的假声,有时在低音部分又显得嘶哑。你的音高可以简化建模为一个分段二次函数 $g$。换句话说,从时间 $0$ 到 $x_1$(不一定与函数 $f$ 的 $x_1$ 相同),你的音高 $g(x)$ 符合某个二次多项式,然后从时间 $x_1$ 到 $x_2$ 符合另一个二次多项式,依此类推。

你的表演 $g$ 与目标旋律 $f$ 之间的差异即为这两个函数之间的面积。参见图 E.1 中的示例。给定旋律 $f$ 和你的表演 $g$,计算它们的差异。

图 E.1:样例输入 1 的示意图。$f$ 和 $g$ 之间的差异即为图中阴影区域的面积。

输入格式

输入的第一行包含一个整数 $n$ ($1 \le n \le 500$),表示目标旋律函数 $f$ 的分段数。接下来 $n$ 行描述 $f$。第 $i$ 行包含两个整数 $x_i$ 和 $y_i$ ($x_{i-1} < x_i \le 10^4$ 且 $0 \le y_i \le 10^4$)。对于半开区间 $[x_{i-1}, x_i)$ 内的所有 $x$,$f(x)$ 的值等于 $y_i$。对于第一个区间,我们定义 $x_0 = 0$。

接下来一行包含一个整数 $m$ ($1 \le m \le 500$),表示描述你表演的函数 $g$ 的分段数。接下来的 $m$ 行包含 $g$ 的描述。第 $i$ 行包含四个整数 $x'_i$、$a_i$、$b_i$ 和 $c_i$ ($x'_{i-1} < x'_i \le 10^4$ 且 $-10^7 \le a_i, b_i, c_i \le 10^7$)。对于半开区间 $[x'_{i-1}, x'_i)$ 内的所有 $x$,$g(x)$ 的值等于 $a_ix^2 + b_ix + c_i$。对于第一个区间,我们定义 $x'_0 = 0$。

你可以假设对于所有 $x'_0 \le x \le x'_m$,都有 $0 \le g(x) \le 10^4$,并且两个函数在同一时间结束(即 $x_n = x'_m$)。

输出格式

输出 $f$ 和 $g$ 之间的差异。你的输出误差应不超过 $10^{-6}$(绝对误差或相对误差)。

样例

样例输入 1

2
3 20
10 10
3
2 2 0 14
4 -4 16 8
10 0 -1 18

样例输出 1

24.7785420704411

样例输入 2

1
20 50
1
20 1 -20 100

样例输出 2

609.47570824873

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.