mirror of
https://github.com/xlucn/PAT.git
synced 2026-10-30 00:37:37 +08:00
25 lines
1.3 KiB
HTML
25 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
<h1>1105. Spiral Matrix (25)</h1>
|
|
<div id="problemContent">
|
|
<p>This time your job is to fill a sequence of N positive integers into a <b>spiral matrix</b> in non-increasing order. A <b>spiral matrix</b> is filled in from the first element at the upper-left corner, then move in a clockwise spiral. The matrix has <b>m</b> rows and <b>n</b> columns, where <b>m</b> and <b>n</b> satisfy the following: <b>m</b>*<b>n</b> must be equal to N; <b>m</b>>=<b>n</b>; and <b>m</b>-<b>n</b> is the minimum of all the possible values.</p>
|
|
<p><b>
|
|
Input Specification:
|
|
</b></p>
|
|
<p>Each input file contains one test case. For each case, the first line gives a positive integer N. Then the next line contains N positive integers to be filled into the spiral matrix. All the numbers are no more than 10<sup>4</sup>. The numbers in a line are separated by spaces.</p>
|
|
<p><b>
|
|
Output Specification:
|
|
</b></p>
|
|
<p>For each test case, output the resulting matrix in <b>m</b> lines, each contains <b>n</b> numbers. There must be exactly 1 space between two adjacent numbers, and no extra space at the end of each line.
|
|
</p>
|
|
<b>Sample Input:</b><pre>
|
|
12
|
|
37 76 20 98 76 42 53 95 60 81 58 93
|
|
</pre>
|
|
<b>Sample Output:</b><pre>
|
|
98 95 93
|
|
42 37 81
|
|
53 20 76
|
|
58 60 76
|
|
</pre>
|
|
</div> |