QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 30

#5835. 捡小鸡

统计

一群小鸡正沿着一条笔直狭窄的道路向东奔跑。每只小鸡都以各自恒定的速度奔跑。每当一只小鸡追上它前面的小鸡时,它就必须减速并以被追上的那只小鸡的速度跟随。你正驾驶着一辆移动起重机在鸡群后方,追赶着向道路尽头的谷仓奔跑的小鸡。起重机的机械臂允许你瞬间抓起任意一只小鸡,让它身后的小鸡从下方通过,然后再将抓起的小鸡放回原处。这个操作不需要时间,且只能对两只紧邻的小鸡进行,即使有 3 只或更多小鸡排成一列也是如此。

给定 $N$ 只小鸡在时间 $0$ 时的初始位置 $X_i$ 和自然速度 $V_i$,以及谷仓的位置 $B$,求为了让至少 $K$ 只小鸡在时间 $T$ 或之前到达谷仓,你需要执行的最少交换次数。

你可以将小鸡视为在直线上移动的点。即使有 3 只或更多小鸡处于同一位置且紧邻,抓起其中一只也只会让另外两只中的一只通过。任何交换都是瞬间完成的,这意味着你可以同时进行多次交换,但每一次交换都计为一次独立的交换。

输入格式

输入的第一行包含测试用例的数量 $C$。接下来是 $C$ 个测试用例。每个测试用例的第一行包含 4 个整数:$N$、$K$、$B$ 和 $T$。下一行包含 $N$ 个递增的整数 $X_i$。再下一行包含 $N$ 个整数 $V_i$。所有距离单位为米,速度单位为米/秒,时间单位为秒。

输出格式

对于每个测试用例,输出一行 "Case #x: $S$",其中 $x$ 是测试用例编号(从 1 开始),$S$ 是所需的最少交换次数,如果无法达到要求,则输出 "IMPOSSIBLE"。

数据范围

$1 \le C \le 100$ $1 \le B \le 1,000,000,000$ $1 \le T \le 1,000$ $0 \le X_i < B$ $1 \le V_i \le 100$ 所有 $X_i$ 均不相同且按递增顺序排列。

小数据集(测试集 1 - 可见;13 分)

$1 \le N \le 10$ $0 \le K \le \min(3, N)$

大数据集(测试集 2 - 隐藏;17 分)

$1 \le N \le 50$ $0 \le K \le N$

样例

输入 1

3
5 3 10 5
0 2 5 6 7
1 1 1 1 4
5 3 10 5
0 2 3 5 7
2 1 1 1 4
5 3 10 5
0 2 3 4 7
2 1 1 1 4

输出 1

Case #1: 0
Case #2: 2
Case #3: IMPOSSIBLE

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.