QOJ.ac

QOJ

Limite de temps : 10 s Limite de mémoire : 2048 MB Points totaux : 14

#12494. 照明优化

Statistiques

Onyaomale 正在领导一个项目,将高速公路沿线的路灯灯泡从白炽灯更换为既节能又强力的 LED 灯泡。她首先拆除了所有旧的白炽灯,现在专注于安装新的 LED 灯泡。由于新灯泡功率更强,Onyaomale 认为某些路灯可能是不必要的,她可以通过不使用它们来节省更多能源。

我们将高速公路建模为一条从西向东延伸、长度为 $M$ 米的直线。第 $x$ 米处是距离高速公路西端 $x$ 米的一个点。如果一盏路灯位于第 $x$ 米处,并且上面安装了一个照明半径为 $R$ 米的灯泡,那么该路灯将照亮高速公路上从第 $\max(0, x - R)$ 米到第 $\min(M, x + R)$ 米(包含端点)的线段。Onyaomale 需要安装灯泡,使得高速公路上的每一个点至少被其中一个灯泡照亮。注意,这包括照亮距离高速公路端点非整数米的点。未安装灯泡的路灯不会提供任何照明。

给定高速公路的长度 $M$(单位:米)、新灯泡的照明半径 $R$(单位:米)以及所有路灯的位置,求 Onyaomale 为了照亮整条高速公路所需安装的灯泡的最小数量,或者报告无法做到这一点。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例包含两行。第一行包含三个整数 $M$、$R$ 和 $N$:分别为高速公路的长度(米)、灯泡的照明半径(米)以及路灯的数量。测试用例的第二行包含 $N$ 个已排序的整数 $X_1, X_2, \dots, X_N$,表示路灯所在的高速公路位置(米)。

输出格式

对于每个测试用例,输出一行 Case #x: y,其中 $x$ 是测试用例编号(从 1 开始),$y$ 是照亮整条高速公路所需安装的灯泡的最小数量(如果可行)。如果无法使用现有的路灯照亮整条高速公路,则 $y$ 应为 IMPOSSIBLE

数据范围

$1 \le T \le 100$ $1 \le M \le 10^9$ $1 \le R \le 10^9$ $0 \le X_1$ $X_i < X_{i+1}$(对于所有 $i$) $X_N \le M$

子任务

测试集 1(可见判决): $1 \le N \le 10$

测试集 2(可见判决): $1 \le N \le 10^5$

样例

样例输入 1

3
10 3 3
2 7 9
10 2 3
2 7 9
10 2 4
2 3 7 9

样例输出 1

Case #1: 2
Case #2: IMPOSSIBLE
Case #3: 4

说明

在样例 1 中,Onyaomale 可以仅通过在最西侧和中间的路灯上安装灯泡来照亮整条高速公路,而让最东侧的路灯保持闲置。通过这两个分别覆盖 $[0, 5]$ 和 $[4, 10]$ 的灯,整条高速公路 $[0, 10]$ 均被照亮。

在样例 2 中,Onyaomale 的配置与样例 1 相同,但灯泡的照明半径更小。在这种情况下,她无法照亮整条高速公路。特别地,即使点亮所有路灯,第 4 米和第 5 米之间的中点仍然无法被照亮。

在样例 3 中,与样例 2 相比,Onyaomale 在第 3 米处多了一盏路灯,而其他条件相同。在这种情况下,在每一盏路灯上都安装灯泡是照亮整条高速公路的唯一方法。

Figure 1. 样例 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.