QOJ.ac

QOJ

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

#14250. 丘陵散步

統計

UCLA 是一个充满山丘的校园,这使得步行变得极其令人厌烦(任何 UCLA 的学生都可以向你证实这一点)。事实上,洛杉矶所有的山丘都是由 $x$ 轴界定的抛物线形状,由公式 $y = -(x - a)^2 + b$ 定义,其中 $a$ 和 $b$ 为整数。然而,如果两个或更多的山丘重叠,就会发生一些特殊的事情。在至少有两个山丘重叠的任何 $x$ 值处,它们会合并成一个超级山丘,其高度定义为所有重叠山丘在每个重叠点处的 $y$ 值之和。例如,如果三个山丘在 $x = 4$ 处的高度分别为 $y_1$、$y_2$ 和 $y_3$,那么在 $x = 4$ 处的超级山丘高度将变为 $y_1 + y_2 + y_3$。UCLA 的校园仅由这些超级山丘组成,这令大多数学生感到沮丧。你非常想向朋友抱怨在 UCLA 散步有多么令人烦恼,因此你想计算校园的多丘度,即这些超级山丘与 $x$ 轴所围成的区域面积。你能计算出这个多丘度值,以便向你的朋友抱怨吗?

图 1:第一个样例的示意图

例如,如果你有两个由方程 $y = -(x - 3)^2 + 5$ 和 $y = -(x - 4)^2 + 4$ 定义的山丘,如上图所示,由于两个山丘在 $x = 2$ 和 $x = 3 + \sqrt{5}$ 之间重叠,因此在此区间内会存在一个超级山丘。多丘度值将是该超级山丘的面积,即图中绿色阴影区域的面积。

输入格式

输入的第一行包含一个整数 $N$,表示山丘的数量,满足 $1 \le N \le 100\,000$。

接下来的 $N$ 行,每行包含两个空格分隔的整数 $a_i$ 和 $b_i$($0 \le a_i, b_i \le 1\,000$),代表山丘 $y = -(x - a_i)^2 + b_i$。

输出格式

输出一行,包含 UCLA 的多丘度值。只要你的答案与标准答案的相对或绝对误差不超过 $10^{-5}$,即被视为正确。

样例

输入样例 1

2
3 5
4 4

输出样例 1

21.768317

输入样例 2

2
1 1
3 1

输出样例 2

0

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.