zoukankan      html  css  js  c++  java
  • 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,可能会数组越界。
  • 相关阅读:
    POJ 1987
    POJ 3107
    POJ 1984
    POJ 1985
    【50】目标检测之目标定位
    【49】计算机视觉现状
    【48】数据扩充(Data augmentation)
    【47】迁移学习(Transfer Learning)
    【46】谷歌 Inception 网络简介Inception(2)
    【45】谷歌 Inception 网络简介Inception(1)
  • 原文地址:https://www.cnblogs.com/zhanghaijie/p/10375588.html
Copyright © 2011-2022 走看看