QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 512 MB 満点: 100

#16959. 跳跃的猫

統計

一个城市的轮廓线由 $n$ 个整数 $d_1, d_2, \dots, d_n$($0 < d_1 < d_2 < \dots < d_n$)和 $n$ 个整数 $h_1, h_2, \dots, h_n$ 确定。

轮廓线表面由 $n$ 条水平线段组成,第 $i$ 条线段连接点 $(d_{i-1}, h_i)$ 和 $(d_i, h_i)$,其中 $d_0 = 0$。每条线段代表一栋建筑的屋顶。

一只猫(体型很小,可以看作一个点)想要从轮廓线的最左端点 $(0, h_1)$ 前往最右端点 $(d_n, h_n)$。为了达到这个目标,猫会进行一系列移动。每次移动是以下两种类型之一:

  1. 步行:从点 $(x_1, y_1)$ 走到点 $(x_2, y_2)$。两个点必须属于同一个表面线段,即存在 $i$ 使得 $y_1 = y_2 = h_i$ 且 $d_{i-1} \le x_1, x_2 \le d_i$。步行的轨迹是一条直线段。
  2. 跳跃:从点 $(x_1, y_1)$ 跳到点 $(x_2, y_2)$。点 $(x_1, y_1)$ 和 $(x_2, y_2)$ 必须属于不同的表面线段。跳跃的轨迹是一条直线段,且必须满足以下约束条件:

    • $(x_1, y_1)$ 与 $(x_2, y_2)$ 之间的距离最多为 $L$;
    • 连接 $(x_1, y_1)$ 和 $(x_2, y_2)$ 的线段不能与任何建筑相交,即不存在属于该线段的点 $(x, y)$ 和整数 $i$,使得 $d_{i-1} < x < d_i$ 且 $y < h_i$。

猫的轨迹长度是其中所有移动长度的总和。求猫从 $(0, h_1)$ 到 $(d_n, h_n)$ 的最短轨迹长度,或者确定目标无法到达。

输入格式

第一行包含两个整数 $n$ 和 $L$($1 \le n \le 50$;$1 \le L \le 100$)。

第二行包含 $n$ 个整数 $d_1, d_2, \dots, d_n$($0 < d_1 < d_2 < \dots < d_n \le 1000$)。

第三行包含 $n$ 个整数 $h_1, h_2, \dots, h_n$($1 \le h_i \le 100$;$h_i \ne h_{i+1}$)。

输出格式

输出一个浮点数,表示从点 $(0, h_1)$ 到点 $(d_n, h_n)$ 的最短轨迹长度。如果不存在可行轨迹,则输出 $-1$。

如果你的答案的绝对误差或相对误差不超过 $10^{-9}$,则被视为正确。

样例

输入样例 1

6 5
3 9 11 12 16 18
5 1 6 2 5 7

输出样例 1

25.83095189484530047

输入样例 2

6 4
3 9 11 12 16 18
5 1 6 2 5 7

输出样例 2

-1

说明

第一个样例的示意图如下所示。

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.