QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100

#8174. 集合构造

Statistics

给定整数 $N \ge 2$ 和整数 $M$,满足 $2 \le M \le \frac{N(N+1)}{2}$。请构造一个包含非负整数的集合 $A$,使其满足以下条件:

  • 若 $x \in A$,则 $0 \le x \le 2^N - 1$。
  • $0 \in A$。
  • $2^N - 1 \in A$。
  • 若 $x, y \in A$,则 $(x \text{ AND } y) \in A$。
  • 若 $x, y \in A$,则 $(x \text{ OR } y) \in A$。
  • $A$ 中的元素个数等于 $M$。

其中,AND 表示按位与运算,OR 表示按位或运算。 给定 $T$ 组测试数据,请分别求解。

输入格式

输入通过标准输入给出,格式如下:

$T$ $case_1$ $case_2$ $\vdots$ $case_T$

每个测试用例 $case_i$ ($1 \le i \le T$) 的格式如下:

$N \ M$

  • 输入中的所有值均为整数。
  • $1 \le T \le 30$
  • $2 \le N \le 60$
  • $2 \le M \le \frac{N(N+1)}{2}$

输出格式

对于每个测试用例,输出 $M$ 个不同的非负整数,构成满足题目所有条件的集合 $A$。你可以以任意顺序输出这些元素。 注意,可以证明在这些约束条件下,有效的答案总是存在的。

样例

样例输入 1

3
3 5
4 8
60 2

样例输出 1

0 1 3 5 7
0 1 3 7 8 9 11 15
0 1152921504606846975

说明

对于第一个测试用例,选择 $A = \{0, 1, 3, 5, 7\}$ 满足题目中的所有条件。 例如,$(3 \text{ AND } 5) = 1 \in A$,且 $(3 \text{ OR } 5) = 7 \in A$。

任何满足条件的集合 $A$ 都是可接受的;例如,输出 ‘7 1 4 0 5’ 也是有效的。输出中的元素不需要按升序排列。

输出 ‘1 2 3 5 7’ 是无效的,因为 $0 \notin A$。 输出 ‘0 3 4 5 7’ 是无效的,因为 $3, 5 \in A$,但 $(3 \text{ AND } 5) = 1 \notin A$。 输出 ‘7 7 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.