1105 Spiral Matrix (25 point(s))
This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasing order. A spiral matrix is filled in from the first element at the upper-left corner, then move in a clockwise spiral. The matrix has m rows and n columns, where m and n satisfy the following: m×n must be equal to N; m≥n; and m−n is the minimum of all the possible values.
Input Specification:
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 104. The numbers in a line are separated by spaces.
Output Specification:
For each test case, output the resulting matrix in m lines, each contains n numbers. There must be exactly 1 space between two adjacent numbers, and no extra space at the end of each line.
Sample Input:
Sample Output:
经验总结:
emmmm 这一题做了这是第三遍了,已经可以独立的写出来了,也是不容易= =、、 这一题弄懂了原理,就很简单,注意只有一个数的特判(不特判第三个测试点会无法通过),以及缩小方块直至方块为1时候的特殊处理(不处理会有测试点超时),就这么多啦~
AC代码