• 1105 Spiral Matrix (25 分)螺旋矩阵


    1105 Spiral Matrix (25 分)

    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; mn; and mn 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:

    12
    37 76 20 98 76 42 53 95 60 81 58 93
    

    Sample Output:

    98 95 93
    42 37 81
    53 20 76
    58 60 76
    思路:
      刚开始写没有思路,感觉递归可以就写了递归,递归写完以后发现其实循环足矣,然后就改成了循环,内层
    循环注意要控制循环变量的范围,因为测试用例中有的n值是素数,这样求得的矩阵是n*1,可能会数组越界。
  • 相关阅读:
    0325JavaScript
    0322css样式表,选择器
    0320表单
    0313函数
    0312数组
    0311类
    0309笔记整理
    进制转换
    Xcode快捷键大全
    Android LearningNotes
  • 原文地址:https://www.cnblogs.com/zhanghaijie/p/10375588.html
Copyright © 2020-2023  润新知