QOJ.ac

QOJ

時間限制: 6 s 記憶體限制: 1024 MB 總分: 42

#5914. 坠落的钻石

统计

钻石正从天而降。人们现在正争相购买钻石可能落地的位置,只为在钻石落地时能拥有一颗。你被推荐了这样一个位置,并想知道这是否是一笔划算的交易。

钻石的形状正如其名:它们是正方形,其顶点分别为 $(X-1, Y)$、$(X, Y+1)$、$(X+1, Y)$ 和 $(X, Y-1)$,其中 $(X, Y)$ 被称为钻石的中心。所有钻石始终位于 $X-Y$ 平面上。$X$ 为水平方向,$Y$ 为垂直方向。地面位于 $Y=0$ 处,$Y$ 坐标为正表示在地面上方。

钻石沿 $Y$ 轴逐个落下。这意味着它们从 $Y$ 值非常大的 $(0, Y)$ 点开始,垂直向下坠落,直到撞击地面或其他钻石。

当钻石撞击地面时,它会一直下落直到中心没入地面,然后停止移动。这实际上意味着如果钻石的中心到达 $Y=0$,它就会停止下落或滑动。

当钻石顶点对顶点地撞击到另一颗钻石时,它可以开始向两个可能的方向之一滑动(不发生旋转):左下或右下。如果两侧都没有钻石阻挡,它将以相等的概率向左或向右滑动。如果一侧有钻石阻挡,下落的钻石将滑向另一侧,直到被另一颗钻石阻挡或没入地面。如果左右两侧的路径都被钻石阻挡,钻石就会直接停止。

考虑图中的例子。第一颗钻石撞击地面并在半没入状态下停止,其中心位于 $(0, 0)$。第二颗钻石可能以相等的概率向左或向右滑动。在这里,它恰好向左滑动。它停在第一颗钻石旁边,没入地面,位置为 $(-2, 0)$。第三颗钻石也会撞击第一颗钻石。然后它要么随机向右滑动并停在地面上,要么向左滑动,停在已放置的两颗钻石之间上方。它再次向左滑动,因此停在 $(-1, 1)$。第四颗钻石别无选择:它将向右滑动,并停在地面上 $(2, 0)$ 的位置。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 行。每行包含三个整数:下落钻石的数量 $N$,以及你感兴趣的位置 $X, Y$。注意,你感兴趣购买的位置不一定在地面上或地面附近。

输出格式

对于每个测试用例,输出一行 "Case #x: p",其中 $x$ 是用例编号(从 1 开始),$p$ 是 $N$ 颗钻石中有一颗落到中心恰好位于 $(X, Y)$ 的概率。如果答案与正确答案的绝对误差在 $10^{-6}$ 以内,则被视为正确。有关这意味着什么以及我们接受的浮点数格式,请参阅 FAQ

数据范围

$1 \le T \le 100$。 $-10,000 \le X \le 10,000$。 $0 \le Y \le 10,000$。 $X + Y$ 为偶数。

子任务 1

$1 \le N \le 20$。

子任务 2

$1 \le N \le 10^6$。

样例

输入 1

7
1 0 0
1 0 2
3 0 0
3 2 0
3 1 1
4 1 1
4 0 2

输出 1

Case #1: 1.0
Case #2: 0.0
Case #3: 1.0
Case #4: 0.75
Case #5: 0.25
Case #6: 0.5
Case #7: 0.0

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.