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,可能会数组越界。
  • 相关阅读:
    欧拉函数、欧拉定理、费马小定理、拓展欧拉定理
    $CF 635 (Div 2)$
    $CF 634 (Div 3)$
    $CF 633 (Div 2)$
    $ACM$ 课第三次作业-搜索
    《信息安全数学基础一》第一章笔记
    接口测试工具与接口测试框架
    【python】基础知识小结
    【mongo】多个字段进行分组查询
    【mongo】去重操作
  • 原文地址:https://www.cnblogs.com/zhanghaijie/p/10375588.html
Copyright © 2011-2022 走看看