QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 128 MB 總分: 100

#1940. 害羞的多边形

统计

给定两个实心多边形及其在 $xy$ 平面上的位置。你可以沿 $x$ 轴移动其中一个多边形(移动过程中它们可以重叠)。你不能在其他方向上移动它。目标是在满足以下条件的前提下,尽可能紧凑地放置它们:一个多边形中的任意一点与另一个多边形中的任意一点之间的距离不得小于给定的最小距离 $L$。

我们将放置的宽度定义为两个多边形中所有点的 $x$ 坐标的最大值与最小值之差。

你的任务是编写一个程序,计算满足上述条件的最小放置宽度。

让我们看一个例子。如果图 13 中的多边形在 $L = 10.0$ 的条件下放置,结果将是 $100$。图 14 展示了其中一种最优放置方式。

图 13:两个多边形的初始位置

图 14:其中一种最优放置方式 ($L = 10.0$)

输入格式

输入包含多个数据集。每个数据集的格式如下:

$L$ $Polygon_1$ $Polygon_2$

$L$ 是一个十进制小数,表示两个多边形所需的最小距离。$L$ 大于 $0.1$ 且小于 $50.0$。

每个多边形的格式如下:

$n$ $x_1 \ y_1$ $x_2 \ y_2$ $\vdots$ $x_n \ y_n$

$n$ 是一个正整数,表示多边形的顶点数。$n$ 大于 $2$ 且小于 $15$。

接下来的行表示多边形的顶点。顶点数据行包含一对非负整数,表示顶点的 $x$ 和 $y$ 坐标。$x$ 和 $y$ 坐标由单个空格分隔,$y$ 坐标后紧跟换行符。$x$ 和 $y$ 均小于 $500$。

多边形的边连接相邻顶点数据行中给出的顶点,以及最后一行和第一行给出的顶点。你可以假设顶点是按逆时针顺序给出的,且多边形的轮廓是简单的,即它们不会自交或接触。

此外,你可以假设结果对误差不敏感。具体来说,对于给定的一对多边形,最小宽度是给定最小距离 $l$ 的函数。设该函数为 $w(l)$。那么你可以假设 $|w(L \pm 10^{-7}) - w(L)| < 10^{-4}$。

输入的结束由仅包含一个零的行表示。该行不属于任何数据集。

输出格式

输出应包含一系列行,每行包含一个十进制小数。每个数字应表示相应数据集的最小宽度。答案的误差不应超过 $0.0001$。只要满足上述精度条件,你可以输出小数点后任意位数的数字。

样例

样例输入 1

10.5235
3
0 0
100 100
0 100
4
0 50
20 50
20 80
0 80
10.0
4
120 45
140 35
140 65
120 55
8
0 0
100 0
100 100
0 100
0 55
80 90
80 10
0 45
10.0
3
0 0
1 0
0 1
3
0 100
1 101
0 101
10.0
3
0 0
1 0
0 100
3
0 50
100 50
0 51
0

样例输出 1

114.882476
100
1
110.5005

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.