QOJ.ac

QOJ

Time Limit: 6 s Memory Limit: 1024 MB Total points: 20

#5920. 许多奖品

Statistics

我们将举办一场有 $2^N$ 支队伍的锦标赛,并向排名为 $0 \dots P-1$ 的队伍颁发 $P$ 个相同的奖品。

队伍编号为 $0$ 到 $2^N-1$。当队伍 $i$ 和队伍 $j$ 对战时,队伍 $i$ 获胜当且仅当 $i < j$。

锦标赛的队伍按某种顺序排列,称为锦标赛的锦标赛列表,其中包含了锦标赛中的所有 $2^N$ 支队伍。锦标赛列表将决定哪些队伍相互对战以及对战的顺序。

你的任务是找出无论锦标赛列表如何排列,都保证能获得奖品的编号最大的队伍;以及找出在某种锦标赛列表排列下,可能获得奖品的编号最大的队伍。

锦标赛规则

锦标赛共进行 $N$ 轮。

每支队伍都有一个战绩:即该队伍目前为止所有比赛结果的列表。例如,如果一支队伍打了三场比赛,第一场赢了,第二场输了,第三场赢了,那么它的战绩就是 [W, L, W]。如果一支队伍还没打过比赛,它的战绩就是 []

在每一轮中,每支队伍都与战绩相同的队伍进行比赛。锦标赛列表中具有特定战绩的第一支队伍将与具有相同战绩的第二支队伍比赛;具有相同战绩的第三支队伍将与第四支队伍比赛,依此类推。

经过 $N$ 轮比赛后,每支队伍的战绩各不相同。队伍按其战绩的字典序逆序排名;即 [W, W, W] > [W, W, L] > [W, L, W] ... > [L, L, L]

以下是一个 $N=3$ 且锦标赛列表为 [2, 4, 5, 3, 6, 7, 1, 0] 的锦标赛示例,其中列代表不同的轮次,队伍按战绩分组。示例中每场比赛的获胜者已用 * 标记。

Round 1    Round 2    Round 3    Final Result
(best rank at top)
[]         [W]        [W,W]
2  *       2  *       2          0  [W,W,W]
4          3          0  *       2  [W,W,L]
                      [W,L]
5          6          3  *       3  [W,L,W]
3  *       0  *       6          6  [W,L,L]
           [L]        [L,W]
6  *       4  *       4          1  [L,W,W]
7          5          1  *       4  [L,W,L]
                      [L,L]
1          7          5  *       5  [L,L,W]
0  *       1  *       7          7  [L,L,L]

如果我们颁发 4 个奖品($N=3, P=4$),奖品将颁发给队伍 0、2、3 和 6。

在 $N=3, P=4$ 的情况下,无论锦标赛列表如何排列,都保证能获得奖品的编号最大的队伍是队伍 0:该锦标赛列表证明了队伍 1 有可能无法获得奖品,而事实证明,无论锦标赛列表如何排列,队伍 0 总能获得奖品。

在 $N=3, P=4$ 的情况下,根据锦标赛列表的排列方式,可能获得奖品的编号最大的队伍是队伍 6:该锦标赛列表证明了队伍 6 有可能获得奖品,而事实证明,无论锦标赛列表如何排列,队伍 7 永远无法获得奖品。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例包含两个空格分隔的整数:$N$(表示锦标赛有 $2^N$ 支队伍)和 $P$(奖品数量)。

输出格式

对于每个测试用例,输出一行 "Case #x: y z",其中 $x$ 是用例编号(从 1 开始),$y$ 是无论锦标赛列表如何排列都保证能获得奖品的编号最大的队伍,$z$ 是在某种锦标赛列表排列下可能获得奖品的编号最大的队伍。

数据范围

$1 \le T \le 100$。 $1 \le P \le 2^N$。

子任务 1

$1 \le N \le 10$。

子任务 2

$1 \le N \le 50$。

样例

样例输入 1

3
3 4
3 5
3 3

样例输出 1

Case #1: 0 6
Case #2: 2 6
Case #3: 0 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.