QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100

#13091. 秘密代码

Statistics

三位特工 $A$、$B$ 和 $C$ 想要确认他们的秘密代码是否相同。为了保密,他们没有约定会面时间。相反,他们决定在一天中的时间间隔 $[0, S]$ 内随机出现在咖啡馆。设 $t_A, t_B, t_C$ 分别表示 $A$、$B$ 和 $C$ 到达咖啡馆的时间。因此,$t_A, t_B, t_C$ 是在时间间隔 $[0, S]$ 内均匀分布的随机数。

代码确认过程如下:先到达的特工会等待后续特工出现,等待时间为预设的等待时间。如果两名特工在咖啡馆相遇,他们会检查代码是否相同。随后,先到达的特工在确认代码后立即离开咖啡馆。第二名特工则会等待直到第三名特工出现在咖啡馆。如果该特工在自己的等待时间内与最后一名特工相遇,则该特工离开咖啡馆。

三位特工 $A$、$B$、$C$ 的等待时间已确定为 $w_A, w_B, w_C$。至关重要的是,每个到达时间 $t_A, t_B, t_C$ 都是 $0$ 到 $S$ 之间的实数(不一定是整数),而每个等待时间 $w_A, w_B, w_C$ 都是满足 $0 < w_A + w_B, w_B + w_C, w_A + w_C < S$ 的正整数。我们假设代码确认过程不耗费时间。如果特工与后到达的特工确认了代码,该特工会立即离开咖啡馆。让我们通过图 G.1 来解释此过程。

图 G.1 四种成功和不成功确认的情况。

成功的代码确认需要三位特工之间至少有两次相遇。当到达顺序为 $A, B, C$ 时,Case-1 和 Case-4 都是成功确认的例子,但 Case-2 和 Case-3 则不是。在 Case-1 中,特工 $A$ 在时间 $x = t_B$ 时离开咖啡馆,而没有等到时间 $t_A + w_A$。很容易看出 Case-2 是不成功的情况。在 Case-2 中,尽管 $A$ 的等待时间与 $B$ 和 $C$ 的等待时间重叠,但 $B$ 无法与 $C$ 确认代码,因为特工 $A$(已经与 $B$ 确认了代码)在时间 $x$ 离开了咖啡馆。因此,无法在 $B$ 和 $C$ 之间确认代码。注意,在 Case-3 和 Case-4 中,$A$ 也在时间 $x$ 离开了咖啡馆。

我们知道成功确认代码的概率取决于四个整数 $(S, w_A, w_B, w_C)$。给定由四个整数 $(S, w_A, w_B, w_C)$ 确定的 $n$ 个不同场景,我们希望根据此确认概率对这 $n$ 个场景进行排序。

给定 $n$ 个场景,编写一个程序,按概率的非递减顺序打印场景索引。

输入格式

程序从标准输入读取数据。输入的第一行包含一个整数 $n$ ($3 \le n \le 20$),表示场景的数量。接下来的 $n$ 行,每行包含四个正整数 $S, w_A, w_B, w_C$,描述一个场景,满足 $0 < w_A + w_B, w_B + w_C, w_A + w_C < S \le 1000$。

输出格式

程序将结果写入标准输出。在一行中按概率的非递减顺序打印 $n$ 个场景的索引。如果对于 $1 \le i < j \le n$,场景 $i$ 和 $j$ 具有相同的概率,则先打印 $i$。

样例

样例输入 1

3
100 12 13 14
110 8 9 15
200 23 30 40

样例输出 1

2 1 3

样例输入 2

6
201 15 16 16
375 30 32 27
900 75 73 67
203 16 17 16
373 31 32 27
895 73 75 66

样例输出 2

1 2 3 6 5 4

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.