Pat-Class B-1050 spiral Matrix

Source: Internet
Author: User

This question requires that the given n positive integers be filled in the "Spiral matrix" in a non-incrementing order ". The so-called "Spiral matrix" refers to filling in the 1st grids in the upper left corner in a clockwise spiral direction starting from the upper left corner. The size of the matrix is m rows and n columns. The conditions are m × n equal to n; m ≥n; and M? N is the minimum value among all possible values.

Input Format:

The input returns a positive integer N in row 1st and n Positive Integers to be filled in row 2nd. All numbers cannot exceed 104. Adjacent numbers are separated by spaces.

Output Format:

Output spiral matrix. N numbers in each row, m rows in total. Adjacent numbers are separated by one space. No extra space is allowed at the end of the line.

Input example:
1237 76 20 98 76 42 53 95 60 81 58 93
Output example:
98 95 9342 37 8153 20 7658 60 76

Pat-Class B-1050 spiral Matrix

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.