QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#13057. 距离

Statistics

两位著名的超级英雄 Cheburator 和 Crocodile-man 正被传送至曼哈顿以打击邪恶势力。 传送器是一台复杂的设备,因此无法确定他们具体会落在哪里。 更准确地说,我们将曼哈顿表示为一个坐标平面,他们可能落入的区域是该平面上的一个多边形。在这个多边形内,每位超级英雄都可能落在任何一点。 进一步明确,每位超级英雄落下的点是独立且均匀随机选取的。我们所说的“均匀”是指面积上的均匀:对于多边形内的任何图形,落入该图形内的概率与该图形的面积成正比。 任务的成功取决于超级英雄着陆后的距离。既然是在曼哈顿,我们感兴趣的自然是曼哈顿距离:对于两个点 $(x_1, y_1)$ 和 $(x_2, y_2)$,其距离为 $|x_1 - x_2| + |y_1 - y_2|$。 请问这两位超级英雄之间距离的期望值是多少?

输入格式

输入文件的第一行包含一个整数 $n$,$1 \le n \le 1000$。接下来的 $n$ 行按顺序(顺时针或逆时针)描述了多边形的顶点。每个顶点由两个整数描述,即其坐标 $x$ 和 $y$,$-1000 \le x, y \le 1000$。

该多边形没有自交或自接触,但可能是非凸的。任意两点之间的距离仍使用上述公式测量,而不考虑多边形的形状——换句话说,最短的“曼哈顿路径”可能部分位于多边形之外。

输出格式

输出一个浮点数,表示两位超级英雄之间距离的期望值。如果你的输出与答案的绝对误差或相对误差在 $10^{-8}$ 以内,则被视为正确。

样例

输入 1

4
0 0
0 1
1 1
1 0

输出 1

0.6666666666666666

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.