QOJ.ac

QOJ

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

#3566. 骑行

统计

在城市中骑自行车出行时,人们往往会花费大量时间等待红绿灯。如果能减少这些浪费的时间,或许你就能准时赶上第一节课了。

请注意,在红灯处损失的时间不仅仅是停在灯前的时间。当绿灯亮起后,自行车加速也需要额外的时间。

在本题中,我们假设自行车出行的理论模型遵循以下规则:

  • 自行车可以向前移动或保持静止,但绝不会向后移动。自行车没有最高速度限制,但请放心,本题不涉及相对论效应。
  • 自行车增加速度的最大加速度为 $0.5$ 米每二次方秒。
  • 自行车可以瞬间将速度降低到零与当前速度之间的任意值。
  • 自行车不能闯红灯。
  • 每个交通信号灯都按照固定的、持续重复的节奏变换红绿灯。(这些交通信号灯不会变黄灯。)

显然,这个理论模型在多个方面偏离了现实。例如,荷兰的骑行者几乎从不停下来等红灯。此外,模型中的自行车可以以无限大的速率减速,而大多数学生的自行车几乎没有制动能力。我们暂时忽略这些差异,专注于理论模型。

题目描述

你在时间 $T = 0$ 时站在 $X = 0$ 的位置,速度为零。 你现在非常匆忙,希望尽快到达 $X = X_{\text{dest}}$ 的位置。 你的任务是找到一种加速和制动的模式,使得你能安全通过所有交通信号灯,并以最早的时间到达 $X_{\text{dest}}$。

在行程中的任何时刻,包括在红灯前,你都可以制动或停车。然而,找到某种方式在绿灯时通过交通信号灯可能会更有效。

输入格式

每个测试用例的输入包含以下内容:

  • 一行包含一个浮点数 $X_{\text{dest}}$ 和一个整数 $L$。 $X_{\text{dest}}$ 是总行程距离(单位:米,$1 \le X_{\text{dest}} \le 10000$); $L$ 是需要通过的交通信号灯数量($0 \le L \le 10$)。
  • $L$ 行描述交通信号灯的信息,按 $X$ 坐标递增的顺序排列。 每行包含 $3$ 个浮点数:
    • $X_i$,交通信号灯距离起点的距离(单位:米,$0 < X_i < X_{\text{dest}}$);
    • $R_i$,该交通信号灯每次红灯持续的时间(单位:秒,$10 \le R_i \le 500$);
    • $G_i$,该交通信号灯每次绿灯持续的时间(单位:秒,$10 \le G_i \le 500$)。

所有交通信号灯在 $T = 0$ 时变为红灯。 交通信号灯 $i$ 在 $T = R_i$ 时第一次变为绿灯。 同一位置不会有超过一个交通信号灯。

输出格式

对于每个测试用例,输出一行,包含一个浮点数:骑行者到达终点的最早时间。 答案应保留小数点后 $3$ 位。 测试用例的设计保证了微小的误差不会导致四舍五入后的最终答案出错。

样例

输入 1

410.0 2
200.0 15.0 15.0
225.0 31.0 10.0
410.0 2
200.0 15.0 15.0
225.0 35.1 15.0
410.0 2
200.0 15.0 15.0
225.0 45.0 10.0

输出 1

41.497
52.623
57.213

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.