QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#15207. 二维格雷码

统计

给定 $n$,请输出一个 $2^n \times 2^n$ 的格雷码矩阵。

格雷码是一种二进制编码方式,其中相邻的数在二进制表示下恰好有一位不同。

在本题中,对于任何满足 $1 \le i, j \le 2^n$ 的 $i$ 和 $j$,$a_{i,j}$ 与 $a_{i,j+1}$、以及 $a_{i,j}$ 与 $a_{i+1,j}$ 在二进制表示下都应该恰好有一位不同。

同时,我们还要求从 $0$ 到 $2^{2n} - 1$ 的每个数字都恰好出现一次。

输入格式

一个整数 $n$($1 \le n \le 8$)。

输出格式

输出一个 $2^n \times 2^n$ 的格雷码矩阵。注意,你应该以十进制表示输出结果。

样例

输入样例 1

2

输出样例 1

0 1 3 2
4 5 7 6
12 13 15 14
8 9 11 10

说明

本题使用 SPECIAL JUDGE,任何满足条件的解都将被接受。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#978EditorialOpen#15207. 2D Gray Code 题解Hussein2026-02-09 11:59:25View

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.