QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 64 MB Total points: 100 Hackable ✓

#6791. 多米诺骨牌平铺

Statistics

Chiaki 有一个 $n \times m$ 的矩形棋盘。她想用多米诺骨牌覆盖这个棋盘,其中多米诺骨牌是一个 $2 \times 1$ 的矩形,要求满足:

  • 棋盘的所有格子都被覆盖,且没有多米诺骨牌重叠或超出棋盘边界。
  • 不存在四个不同多米诺骨牌的角汇聚于同一点的情况。

下图展示了一些禁止的配置:

下图展示了两个 $4 \times 4$ 棋盘的合法平铺方式:

你还需要给棋盘上的多米诺骨牌编号,使得没有两个多米诺骨牌具有相同的编号。你可以使用从 $1$ 到 $n \times m$ 的数字。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$,表示测试数据的组数。对于每组测试数据:

第一行包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 100$),表示矩形棋盘的大小。 保证所有测试数据的 $n \times m$ 之和不超过 $2 \times 10^6$。

输出格式

对于每组测试数据,输出上述合法的棋盘平铺方案。合法的棋盘由 $n$ 行组成,每行包含 $m$ 个整数。输出中的每个整数代表一个多米诺骨牌的 $id$。共享相同 $id$ 的格子属于同一个多米诺骨牌。

如果不存在解决方案,则输出 “Impossible!”(不含引号)。

样例

输入 1

3
1 1
4 3
4 4

输出 1

Impossible!
1 1 2
3 4 2
3 4 5
6 6 5
1 1 2 2
3 4 4 5
3 6 6 5
7 7 8 8

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.