QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#20031. 美丽的正方形

Statistics

Harry 喜欢画画,也喜欢正方形。今天,Harry 要画一个正方形。

Harry 的正方形可以划分成 $n\cdot n$ 个单位正方形。我们把各行从上到下编号为 $1$ 到 $n$,类似地,把各列从左到右编号为 $1$ 到 $n$。

Harry 将在每个单位正方形中写下一个 $1$ 到 $n\cdot n$ 之间的整数。按照 Harry 的说法,一个正方形是美丽的,当且仅当它满足以下条件:

  • 从 $1$ 到 $n\cdot n$ 的每个整数都恰好写在一个格子中。
  • 对于从 $1$ 到 $n\cdot n-1$ 的每个 $i$,整数 $i$ 和 $i+1$ 必须写在两个共用一条边的单位正方形中。

Harry 已经画好了一个大小为 $n$ 的正方形,并在某个格子中写下了整数 $1$。请帮助 Harry 写下从 $2$ 到 $n\cdot n$ 的整数,构成一个美丽的正方形。

输入格式

输入的第一行包含一个整数 $t$($1\le t\le100$),表示测试用例数量。随后是 $t$ 个测试用例,每个测试用例在一行中包含三个整数 $n$、$r$ 和 $c$($1\le r,c\le n\le100$),其中:

  • $n$ 表示 Harry 所画的正方形的大小。
  • $r$ 和 $c$ 是包含整数 $1$ 的单位正方形所在的行和列。

输出格式

对于每个测试用例:

  • 如果无法构成一个美丽的正方形,输出一行,包含 NO。
  • 否则,输出 YES,接下来输出 $n$ 行,每行恰好包含 $n$ 个整数,表示这个美丽的正方形。如果存在多个解,可以输出其中任意一个。

样例

输入格式 1

2
4 1 1
5 1 2

输出格式 1

YES
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
NO

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.